Skip to content

Commit

Permalink
feat: add obfuscate confirmation modal (#2387)
Browse files Browse the repository at this point in the history
  • Loading branch information
valerydluski authored Dec 10, 2023
1 parent 1ebba35 commit 0b48c5e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 11 deletions.
20 changes: 9 additions & 11 deletions client/src/components/Profile/MainCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,8 +19,6 @@ type Props = {
updateProfile: (data: UpdateProfileInfoDto) => Promise<boolean>;
};

const profileApi = new ProfileApi();

const MainCard = ({ data, isAdmin, isEditingModeEnabled, updateProfile }: Props) => {
const { githubId, name, location, publicCvUrl } = data;
const [isProfileSettingsVisible, setIsProfileSettingsVisible] = useState(false);
Expand All @@ -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);
Expand Down Expand Up @@ -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 (
<>
<ObfuscationModal
open={isObfuscateModalVisible}
githubId={githubId}
setIsModalVisible={setIsObfuscateModalVisible}
/>
<Card style={{ position: 'relative' }}>
{isEditingModeEnabled ? (
<EditOutlined
Expand Down Expand Up @@ -131,7 +129,7 @@ const MainCard = ({ data, isAdmin, isEditingModeEnabled, updateProfile }: Props)
) : null}
{isAdmin ? (
<Paragraph style={{ textAlign: 'center', marginTop: 20 }}>
<Button danger onClick={obfuscateProfile}>
<Button danger onClick={() => setIsObfuscateModalVisible(true)}>
Obfuscate
</Button>
</Paragraph>
Expand Down
64 changes: 64 additions & 0 deletions client/src/components/Profile/ObfuscateConfirmationModal.tsx
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;

0 comments on commit 0b48c5e

Please sign in to comment.