-
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add obfuscate confirmation modal (#2387)
- Loading branch information
1 parent
1ebba35
commit 0b48c5e
Showing
2 changed files
with
73 additions
and
11 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
64 changes: 64 additions & 0 deletions
64
client/src/components/Profile/ObfuscateConfirmationModal.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 { useState } from 'react'; | ||
import { Modal, Input, Typography, Space } from 'antd'; | ||
import { ProfileApi } from 'api'; | ||
|
||
const { Text, Paragraph } = Typography; | ||
|
||
type Props = { | ||
githubId: string | null; | ||
setIsModalVisible: (value: boolean) => void; | ||
open: boolean; | ||
}; | ||
|
||
const profileApi = new ProfileApi(); | ||
|
||
const ObfuscationModal = ({ githubId, setIsModalVisible, open }: Props) => { | ||
const [inputValue, setInputValue] = useState(''); | ||
const [isInputValid, setIsInputValid] = useState(true); | ||
|
||
const handleOk = async () => { | ||
if (githubId && inputValue === githubId) { | ||
await profileApi.obfuscateProfile(githubId); | ||
window.location.reload(); | ||
} else { | ||
setIsInputValid(false); | ||
} | ||
}; | ||
|
||
const handleCancel = () => { | ||
setIsModalVisible(false); | ||
setInputValue(''); | ||
setIsInputValid(true); | ||
}; | ||
|
||
return ( | ||
<Modal open={open} title="Confirm GitHub Profile Obfuscation" onOk={handleOk} onCancel={handleCancel}> | ||
<Space direction="vertical"> | ||
<Paragraph> | ||
<Text> | ||
Please type the GitHub nickname <Text strong>"{githubId}"</Text> to confirm obfuscation. | ||
</Text> | ||
</Paragraph> | ||
<Paragraph type="warning"> | ||
<Text strong type="danger"> | ||
Warning: | ||
</Text>{' '} | ||
Once initiated, the obfuscation process cannot be canceled. Upon completion, all user data will be permanently | ||
deleted and this action is irreversible. Please verify the GitHub nickname and proceed with extreme caution. | ||
</Paragraph> | ||
<Input | ||
placeholder="Enter GitHub nickname" | ||
value={inputValue} | ||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { | ||
setInputValue(e.target.value); | ||
setIsInputValid(true); | ||
}} | ||
status={isInputValid ? '' : 'error'} | ||
/> | ||
{!isInputValid && <Text type="danger">Nickname does not match. Please try again.</Text>} | ||
</Space> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ObfuscationModal; |