-
-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): add leave tenant button in tenant settings (#5600)
- Loading branch information
1 parent
2b5e6d6
commit 4e59064
Showing
4 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/console/src/pages/TenantSettings/TenantBasicSettings/LeaveCard/index.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@use '@/scss/underscore' as _; | ||
|
||
.container { | ||
display: flex; | ||
align-items: center; | ||
border: 1px solid var(--color-divider); | ||
border-radius: _.unit(2); | ||
padding: _.unit(4); | ||
|
||
.description { | ||
flex: 1; | ||
margin-right: _.unit(2); | ||
font: var(--font-body-2); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/console/src/pages/TenantSettings/TenantBasicSettings/LeaveCard/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useContext, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { useAuthedCloudApi } from '@/cloud/hooks/use-cloud-api'; | ||
import FormCard from '@/components/FormCard'; | ||
import { TenantsContext } from '@/contexts/TenantsProvider'; | ||
import Button from '@/ds-components/Button'; | ||
import FormField from '@/ds-components/FormField'; | ||
import { useConfirmModal } from '@/hooks/use-confirm-modal'; | ||
import useCurrentUser from '@/hooks/use-current-user'; | ||
|
||
import * as styles from './index.module.scss'; | ||
|
||
function LeaveCard() { | ||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); | ||
const { show: showModal } = useConfirmModal(); | ||
const api = useAuthedCloudApi(); | ||
const { currentTenantId, removeTenant, navigateTenant } = useContext(TenantsContext); | ||
const { user } = useCurrentUser(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const onClickLeave = async () => { | ||
const [confirm] = await showModal({ | ||
ModalContent: t('tenants.leave_tenant_modal.description'), | ||
type: 'confirm', | ||
confirmButtonText: 'tenants.leave_tenant_modal.leave_button', | ||
}); | ||
|
||
if (!confirm || !user) { | ||
return; | ||
} | ||
|
||
setIsLoading(true); | ||
try { | ||
await api.delete(`/api/tenants/:tenantId/members/:userId`, { | ||
params: { tenantId: currentTenantId, userId: user.id }, | ||
}); | ||
removeTenant(currentTenantId); | ||
navigateTenant(''); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<FormCard title="tenants.leave_tenant_card.leave_tenant"> | ||
<FormField title="tenants.leave_tenant_card.leave_tenant"> | ||
<div className={styles.container}> | ||
<div className={styles.description}> | ||
{t('tenants.leave_tenant_card.leave_tenant_description')} | ||
</div> | ||
<Button | ||
type="default" | ||
title="tenants.leave_tenant_card.leave_tenant" | ||
isLoading={isLoading} | ||
onClick={onClickLeave} | ||
/> | ||
</div> | ||
</FormField> | ||
</FormCard> | ||
); | ||
} | ||
|
||
export default LeaveCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters