forked from novuhq/novu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e72a2f4
commit 3e77f78
Showing
5 changed files
with
124 additions
and
1 deletion.
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
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
59 changes: 59 additions & 0 deletions
59
apps/web/src/pages/settings/tabs/components/ConfirmRegenerationModal.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,59 @@ | ||
import { Group, Modal, useMantineTheme } from '@mantine/core'; | ||
import { Button, colors, shadows, Title, Text } from '../../design-system'; | ||
|
||
export function ConfirmRegenerationModal({ | ||
isOpen, | ||
cancelAction, | ||
confirmAction, | ||
}: { | ||
isOpen: boolean; | ||
cancelAction: () => void; | ||
confirmAction: () => void; | ||
}) { | ||
const theme = useMantineTheme(); | ||
|
||
return ( | ||
<> | ||
<Modal | ||
opened={isOpen} | ||
overlayColor={theme.colorScheme === 'dark' ? colors.BGDark : colors.BGLight} | ||
overlayOpacity={0.7} | ||
styles={{ | ||
modal: { | ||
backgroundColor: theme.colorScheme === 'dark' ? colors.B15 : colors.white, | ||
}, | ||
body: { | ||
paddingTop: '5px', | ||
}, | ||
inner: { | ||
paddingTop: '180px', | ||
}, | ||
}} | ||
title={<Title size={2}>Caution</Title>} | ||
sx={{ backdropFilter: 'blur(10px)' }} | ||
shadow={theme.colorScheme === 'dark' ? shadows.dark : shadows.medium} | ||
radius="md" | ||
size="lg" | ||
onClose={() => { | ||
cancelAction(); | ||
}} | ||
> | ||
<div> | ||
<Text> | ||
You are about to X. This action is irreversible and will render | ||
inoperative the access to the API of all your applications that use | ||
the current key. Proceed anyway? | ||
</Text> | ||
<Group position="right"> | ||
<Button variant="outline" size="md" mt={30} onClick={() => cancelAction()}> | ||
No | ||
</Button> | ||
<Button mt={30} size="md" onClick={() => confirmAction()}> | ||
Yes | ||
</Button> | ||
</Group> | ||
</div> | ||
</Modal> | ||
</> | ||
); | ||
} |
58 changes: 58 additions & 0 deletions
58
apps/web/src/pages/settings/tabs/components/Regenerate.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,58 @@ | ||
import { Button, Text } from '../../../../design-system'; | ||
import { useState } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { useMutation } from 'react-query'; | ||
import { regenerateApiKeys } from '../../../../api/environment'; | ||
import { useEnvController } from '../../../../store/use-env-controller'; | ||
import { ConfirmRegenerationModal } from './ConfirmRegenerationModal'; | ||
|
||
export const Regenerate = () => { | ||
const { refetchEnvironment } = useEnvController(); | ||
const [isModalOpened, setModalIsOpened] = useState(false); | ||
|
||
const { mutateAsync: regenerateApiKeysMutation } = useMutation< | ||
{ key: string }[], | ||
{ error: string; message: string; statusCode: number } | ||
>(regenerateApiKeys); | ||
|
||
async function regenerate() { | ||
await regenerateApiKeysMutation(); | ||
await refetchEnvironment(); | ||
} | ||
|
||
async function handleModal() { | ||
setModalIsOpened(true); | ||
} | ||
|
||
function cancelAction() { | ||
setModalIsOpened(false); | ||
} | ||
|
||
async function confirmAction() { | ||
await regenerate(); | ||
setModalIsOpened(false); | ||
} | ||
|
||
return ( | ||
<> | ||
<div> | ||
<Title>Regenerate API key</Title> | ||
<Button mb={20} mt={10} data-test-id="show-regenerate-api-key-modal" onClick={() => handleModal()}> | ||
Regenerate | ||
</Button> | ||
</div> | ||
<ConfirmRegenerationModal | ||
isOpen={isModalOpened} | ||
cancelAction={cancelAction} | ||
confirmAction={confirmAction} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
|
||
const Title = styled(Text)` | ||
padding-bottom: 17px; | ||
font-size: 20px; | ||
font-weight: 700; | ||
`; |