0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

fix(console): direct to new created tenant and clear create modal on open (#4051)

This commit is contained in:
Darcy Ye 2023-06-19 15:06:06 +08:00 committed by GitHub
parent ad44f0875a
commit 013022d24f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 19 deletions

View file

@ -46,6 +46,7 @@ function CreateTenantModal({ isOpen, onClose }: Props) {
defaultValues: { tag: TenantTag.Development },
});
const {
reset,
control,
handleSubmit,
formState: { errors, isSubmitting },
@ -58,7 +59,7 @@ function CreateTenantModal({ isOpen, onClose }: Props) {
try {
const { name, tag } = data;
const newTenant = await cloudApi.post('/api/tenants', { body: { name, tag } });
reset();
onClose(newTenant);
} catch (error: unknown) {
toast.error(error instanceof Error ? error.message : String(error));

View file

@ -115,6 +115,7 @@ function TenantSelector() {
if (tenant) {
toast.success(t('tenants.tenant_created', { name: tenant.name }));
void mutate();
window.location.assign(new URL(`/${tenant.id}`, window.location.origin).toString());
}
setShowCreateTenantModal(false);
}}

View file

@ -154,10 +154,10 @@ describe('smoke testing for cloud', () => {
'div[class$=ReactModalPortal] div[class*=card][class$=medium] div[class$=footer] button[type=submit]'
);
expect(new URL(page.url()).pathname.endsWith(`${defaultTenantId}/get-started`)).toBeTruthy();
expect(new URL(page.url()).pathname.endsWith(`/get-started`)).toBeTruthy();
});
it('check current tenant list and switch to new tenant', async () => {
it('should navigate to the new tenant', async () => {
// Wait for toast to disappear.
await page.waitForTimeout(5000);
@ -165,25 +165,10 @@ describe('smoke testing for cloud', () => {
const currentTenantCard = await page.waitForSelector(
'div[class$=topbar] > div[class$=currentTenantCard][role=button]:has(div[class$=name])'
);
await expect(currentTenantCard).toMatchElement('div[class$=name]', { text: 'My Project' });
await currentTenantCard.click();
const newTenant = await page.waitForSelector(
'div[class$=ReactModalPortal] div[class$=dropdownContainer] div[class$=dropdownItem]:first-child'
);
await expect(newTenant).toMatchElement('div[class$=dropdownName]', { text: createTenantName });
await newTenant.click();
await page.waitForNavigation({ waitUntil: 'networkidle0' });
await expect(currentTenantCard).toMatchElement('div[class$=name]', { text: createTenantName });
});
it('can sign out of admin console', async () => {
// Check if the current tenant is switched to new tenant.
const currentTenantCard = await page.waitForSelector(
'div[class$=topbar] > div[class$=currentTenantCard][role=button]:has(div[class$=name])'
);
await expect(currentTenantCard).toMatchElement('div[class$=name]', { text: createTenantName });
const userInfoButton = await page.waitForSelector('div[class$=topbar] > div[class$=container]');
await userInfoButton.click();