From 0b48c5e8f6295d3b983b58d3d5d2852fd7866736 Mon Sep 17 00:00:00 2001 From: Valery <57412523+valerydluski@users.noreply.github.com> Date: Sun, 10 Dec 2023 17:17:56 +0100 Subject: [PATCH] feat: add obfuscate confirmation modal (#2387) --- client/src/components/Profile/MainCard.tsx | 20 +++--- .../Profile/ObfuscateConfirmationModal.tsx | 64 +++++++++++++++++++ 2 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 client/src/components/Profile/ObfuscateConfirmationModal.tsx diff --git a/client/src/components/Profile/MainCard.tsx b/client/src/components/Profile/MainCard.tsx index d6d2f40c41..71fde9141f 100644 --- a/client/src/components/Profile/MainCard.tsx +++ b/client/src/components/Profile/MainCard.tsx @@ -6,8 +6,9 @@ import { GithubAvatar } from 'components/GithubAvatar'; import { LocationSelect } from 'components/Forms'; import { Location } from 'common/models/profile'; import ProfileSettingsModal from './ProfileSettingsModal'; -import { ProfileApi, UpdateProfileInfoDto } from 'api'; +import { UpdateProfileInfoDto } from 'api'; import { ProfileMainCardData } from 'services/user'; +import ObfuscationModal from './ObfuscateConfirmationModal'; const { Title, Paragraph, Text } = Typography; @@ -18,8 +19,6 @@ type Props = { updateProfile: (data: UpdateProfileInfoDto) => Promise; }; -const profileApi = new ProfileApi(); - const MainCard = ({ data, isAdmin, isEditingModeEnabled, updateProfile }: Props) => { const { githubId, name, location, publicCvUrl } = data; const [isProfileSettingsVisible, setIsProfileSettingsVisible] = useState(false); @@ -28,6 +27,7 @@ const MainCard = ({ data, isAdmin, isEditingModeEnabled, updateProfile }: Props) const [displayLocation, setDisplayLocation] = useState(location); const [nameInputValue, setNameInputValue] = useState(displayName); const [locationSelectValue, setLocationSelectValue] = useState(displayLocation); + const [isObfuscateModalVisible, setIsObfuscateModalVisible] = useState(false); const showProfileSettings = () => { setIsProfileSettingsVisible(true); @@ -83,15 +83,13 @@ const MainCard = ({ data, isAdmin, isEditingModeEnabled, updateProfile }: Props) setIsSaveDisabled(!readyToUpdate); }, [nameInputValue, locationSelectValue, displayName, displayLocation]); - const obfuscateProfile = async () => { - if (githubId) { - await profileApi.obfuscateProfile(githubId); - } - window.location.reload(); - }; - return ( <> + {isEditingModeEnabled ? ( - diff --git a/client/src/components/Profile/ObfuscateConfirmationModal.tsx b/client/src/components/Profile/ObfuscateConfirmationModal.tsx new file mode 100644 index 0000000000..f4ed12b634 --- /dev/null +++ b/client/src/components/Profile/ObfuscateConfirmationModal.tsx @@ -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 ( + + + + + Please type the GitHub nickname "{githubId}" to confirm obfuscation. + + + + + Warning: + {' '} + 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. + + ) => { + setInputValue(e.target.value); + setIsInputValid(true); + }} + status={isInputValid ? '' : 'error'} + /> + {!isInputValid && Nickname does not match. Please try again.} + + + ); +}; + +export default ObfuscationModal;