-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): add pages to delete service account and token (#825)
* feat: add page to delete service account * feat: add page to revoke service account key * fix: delete loading state * chore: update css variables
- Loading branch information
Showing
10 changed files
with
319 additions
and
26 deletions.
There are no files selected for viewing
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
104 changes: 104 additions & 0 deletions
104
sdks/js/packages/core/react/components/organization/api-keys/delete.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,104 @@ | ||
import { Dialog, Separator, Image } from '@raystack/apsara'; | ||
import styles from './styles.module.css'; | ||
import { Button, Flex, Text, toast } from '@raystack/apsara/v1'; | ||
import cross from '~/react/assets/cross.svg'; | ||
import { useNavigate, useParams } from '@tanstack/react-router'; | ||
import { useFrontier } from '~/react/contexts/FrontierContext'; | ||
import { useState } from 'react'; | ||
|
||
export const DeleteServiceAccount = () => { | ||
const { id } = useParams({ from: '/api-keys/$id/delete' }); | ||
const navigate = useNavigate({ from: '/api-keys/$id/delete' }); | ||
const { client, activeOrganization: organization } = useFrontier(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const orgId = organization?.id; | ||
|
||
async function onDeleteClick() { | ||
try { | ||
setIsLoading(true); | ||
await client?.frontierServiceDeleteServiceUser(id, { org_id: orgId }); | ||
navigate({ | ||
to: '/api-keys', | ||
state: { | ||
refetch: true | ||
} | ||
}); | ||
toast.success('Service account deleted'); | ||
} catch (err: any) { | ||
toast.error('Unable to delete service account', { | ||
description: err?.message | ||
}); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
} | ||
|
||
function onCancel() { | ||
navigate({ to: '/api-keys' }); | ||
} | ||
|
||
return ( | ||
<Dialog open={true}> | ||
{/* @ts-ignore */} | ||
<Dialog.Content | ||
overlayClassname={styles.overlay} | ||
className={styles.addDialogContent} | ||
> | ||
<Flex justify="between" className={styles.addDialogForm}> | ||
<Text size={6} weight={500}> | ||
Delete Service Account | ||
</Text> | ||
|
||
<Image | ||
alt="cross" | ||
style={{ cursor: 'pointer' }} | ||
// @ts-ignore | ||
src={cross} | ||
onClick={() => navigate({ to: '/api-keys' })} | ||
data-test-id="frontier-sdk-delete-service-account-close-btn" | ||
/> | ||
</Flex> | ||
<Separator /> | ||
|
||
<Flex | ||
direction="column" | ||
gap="medium" | ||
className={styles.addDialogFormContent} | ||
> | ||
<Text> | ||
This is an irreversible and permanent action doing this might result | ||
in deletion of the service account and the keys associated with it. | ||
Do you wish to proceed? | ||
</Text> | ||
</Flex> | ||
<Separator /> | ||
<Flex | ||
justify="end" | ||
className={styles.addDialogFormBtnWrapper} | ||
gap={'medium'} | ||
> | ||
<Button | ||
variant="secondary" | ||
size="normal" | ||
data-test-id="frontier-sdk-delete-service-account-cancel-btn" | ||
onClick={onCancel} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="danger" | ||
size="normal" | ||
data-test-id="frontier-sdk-delete-service-account-confirm-btn" | ||
loading={isLoading} | ||
disabled={isLoading} | ||
onClick={onDeleteClick} | ||
loaderText="Deleting..." | ||
> | ||
I Understand and Delete | ||
</Button> | ||
</Flex> | ||
</Dialog.Content> | ||
</Dialog> | ||
); | ||
}; |
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
114 changes: 114 additions & 0 deletions
114
sdks/js/packages/core/react/components/organization/api-keys/service-user/delete.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,114 @@ | ||
import { Dialog, Separator, Image } from '@raystack/apsara'; | ||
import styles from './styles.module.css'; | ||
import { Button, Flex, Text, toast } from '@raystack/apsara/v1'; | ||
import cross from '~/react/assets/cross.svg'; | ||
import { useNavigate, useParams } from '@tanstack/react-router'; | ||
import { useFrontier } from '~/react/contexts/FrontierContext'; | ||
import { useState } from 'react'; | ||
import { DEFAULT_API_PLATFORM_APP_NAME } from '~/react/utils/constants'; | ||
|
||
export const DeleteServiceAccountKey = () => { | ||
const { id, tokenId } = useParams({ | ||
from: '/api-keys/$id/key/$tokenId/delete' | ||
}); | ||
const navigate = useNavigate({ from: '/api-keys/$id/key/$tokenId/delete' }); | ||
const { client, config } = useFrontier(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
async function onDeleteClick() { | ||
try { | ||
setIsLoading(true); | ||
await client?.frontierServiceDeleteServiceUserToken(id, tokenId); | ||
navigate({ | ||
to: '/api-keys/$id', | ||
params: { | ||
id: id | ||
}, | ||
state: { | ||
refetch: true | ||
} | ||
}); | ||
toast.success('Service account key revoked'); | ||
} catch (err: any) { | ||
toast.error('Unable to revoke service account key', { | ||
description: err?.message | ||
}); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
} | ||
|
||
function onCancel() { | ||
navigate({ | ||
to: '/api-keys/$id', | ||
params: { | ||
id: id | ||
} | ||
}); | ||
} | ||
const appName = config?.apiPlatform?.appName || DEFAULT_API_PLATFORM_APP_NAME; | ||
|
||
return ( | ||
<Dialog open={true}> | ||
{/* @ts-ignore */} | ||
<Dialog.Content | ||
overlayClassname={styles.overlay} | ||
className={styles.addDialogContent} | ||
> | ||
<Flex justify="between" className={styles.addDialogForm}> | ||
<Text size={6} weight={500}> | ||
Revoke API Key | ||
</Text> | ||
|
||
<Image | ||
alt="cross" | ||
style={{ cursor: 'pointer' }} | ||
// @ts-ignore | ||
src={cross} | ||
onClick={onCancel} | ||
data-test-id="frontier-sdk-revoke-service-account-key-close-btn" | ||
/> | ||
</Flex> | ||
<Separator /> | ||
|
||
<Flex | ||
direction="column" | ||
gap="medium" | ||
className={styles.addDialogFormContent} | ||
> | ||
<Text> | ||
This is an irreversible action doing this might lead to | ||
discontinuation of access to the {appName} features. Do you wish to | ||
proceed? | ||
</Text> | ||
</Flex> | ||
<Separator /> | ||
<Flex | ||
justify="end" | ||
className={styles.addDialogFormBtnWrapper} | ||
gap={'medium'} | ||
> | ||
<Button | ||
variant="secondary" | ||
size="normal" | ||
data-test-id="frontier-sdk-revoke-service-account-key-cancel-btn" | ||
onClick={onCancel} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="danger" | ||
size="normal" | ||
data-test-id="frontier-sdk-revoke-service-account-key-confirm-btn" | ||
loading={isLoading} | ||
disabled={isLoading} | ||
onClick={onDeleteClick} | ||
loaderText="Revoking..." | ||
> | ||
Revoke | ||
</Button> | ||
</Flex> | ||
</Dialog.Content> | ||
</Dialog> | ||
); | ||
}; |
Oops, something went wrong.