-
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.
Merge branch 'main' into dedicated-iv-per-payload
- Loading branch information
Showing
11 changed files
with
261 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
26 changes: 26 additions & 0 deletions
26
packages/owner-app/src/components/OwnerAlerts/CriticalOwnerAlerts.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,26 @@ | ||
import { Toast, t } from '@youfoundation/common-app'; | ||
import { useAccountRemoval } from '../../hooks/removal/useAccountRemoval'; | ||
|
||
export const CriticalOwnerAlerts = () => { | ||
const { | ||
status: { data: statusData }, | ||
} = useAccountRemoval(); | ||
|
||
const isScheduledForDeletion = !!statusData?.plannedDeletionDate; | ||
|
||
if (!isScheduledForDeletion) return null; | ||
|
||
const date = new Date(statusData.plannedDeletionDate as number); | ||
|
||
return ( | ||
<div className="fixed bottom-2 left-2 right-2 z-50 grid grid-flow-row gap-4 sm:bottom-auto sm:left-auto sm:right-8 sm:top-8"> | ||
<Toast | ||
type={'critical'} | ||
title={`${t( | ||
'Your account is scheduled for deletion' | ||
)} ${date.toLocaleDateString()}. Click for info`} | ||
href="/owner/settings/delete" | ||
/> | ||
</div> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||
import { useDotYouClient } from '@youfoundation/common-app'; | ||
import { | ||
accountDeletionStatus, | ||
markAccountDeletion, | ||
unmarkAccountDeletion, | ||
} from '../../provider/system/RemoveProvider'; | ||
|
||
export const useAccountRemoval = () => { | ||
const queryClient = useQueryClient(); | ||
const dotYouClient = useDotYouClient().getDotYouClient(); | ||
|
||
const getAccountDeletionStatus = async () => { | ||
return accountDeletionStatus(dotYouClient); | ||
}; | ||
|
||
const markDeletion = async (currentPassword: string) => { | ||
return await markAccountDeletion(dotYouClient, currentPassword); | ||
}; | ||
|
||
const unMarkDeletion = async (currentPassword: string) => { | ||
return await unmarkAccountDeletion(dotYouClient, currentPassword); | ||
}; | ||
|
||
return { | ||
status: useQuery({ queryKey: ['removal-status'], queryFn: getAccountDeletionStatus }), | ||
delete: useMutation({ | ||
mutationFn: markDeletion, | ||
onSettled: () => { | ||
queryClient.invalidateQueries({ queryKey: ['removal-status'] }); | ||
}, | ||
}), | ||
undelete: useMutation({ | ||
mutationFn: unMarkDeletion, | ||
onSettled: () => { | ||
queryClient.invalidateQueries({ queryKey: ['removal-status'] }); | ||
}, | ||
}), | ||
}; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { DotYouClient, DriveDefinition, TargetDrive } from '@youfoundation/js-lib/core'; | ||
import { getNonce } from '../auth/AuthenticationProvider'; | ||
import { prepareAuthPassword } from '../auth/AuthenticationHelper'; | ||
|
||
export interface DriveDefinitionParam extends Omit<DriveDefinition, 'targetDriveInfo'> { | ||
targetDrive: TargetDrive; | ||
} | ||
|
||
//Handles management of the System | ||
const root = '/security'; | ||
|
||
//api/owner/v1/security/delete-account | ||
export const markAccountDeletion = async (dotYouClient: DotYouClient, currentPassword: string) => { | ||
const noncePackage = await getNonce(dotYouClient); | ||
const currentAuthenticationPasswordReply = await prepareAuthPassword( | ||
currentPassword, | ||
noncePackage | ||
); | ||
|
||
const client = dotYouClient.createAxiosClient(); | ||
const url = root + '/delete-account'; | ||
|
||
return client.post(url, { currentAuthenticationPasswordReply }).then((response) => { | ||
return response.status === 200; | ||
}); | ||
}; | ||
|
||
//api/owner/v1/security/undelete-account | ||
export const unmarkAccountDeletion = async ( | ||
dotYouClient: DotYouClient, | ||
currentPassword: string | ||
) => { | ||
const noncePackage = await getNonce(dotYouClient); | ||
const currentAuthenticationPasswordReply = await prepareAuthPassword( | ||
currentPassword, | ||
noncePackage | ||
); | ||
|
||
const client = dotYouClient.createAxiosClient(); | ||
const url = root + '/undelete-account'; | ||
|
||
return client.post(url, { currentAuthenticationPasswordReply }).then((response) => { | ||
return response.status === 200; | ||
}); | ||
}; | ||
|
||
//api/owner/v1/security/account-status | ||
export const accountDeletionStatus = async (dotYouClient: DotYouClient) => { | ||
const client = dotYouClient.createAxiosClient(); | ||
const url = root + '/account-status'; | ||
|
||
return client.get<AccountDeletionStatus>(url).then((response) => { | ||
return response.data; | ||
}); | ||
}; | ||
|
||
export interface AccountDeletionStatus { | ||
plannedDeletionDate?: number; | ||
planId: string; | ||
} |
116 changes: 116 additions & 0 deletions
116
packages/owner-app/src/templates/Settings/DeleteAccountSettings.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,116 @@ | ||
import { t, Alert, ActionButton, Label, Input } from '@youfoundation/common-app'; | ||
import { useEffect, useState } from 'react'; | ||
import Section from '../../components/ui/Sections/Section'; | ||
import { useAccountRemoval } from '../../hooks/removal/useAccountRemoval'; | ||
|
||
export const DeleteAccountSettings = () => { | ||
const [currentPassword, setCurrentPassword] = useState(''); | ||
const { | ||
status: { data: statusData }, | ||
delete: { mutate: deleteAccount, status: deleteStatus }, | ||
undelete: { mutate: undeleteAccount, status: undeleteStatus }, | ||
} = useAccountRemoval(); | ||
|
||
const isScheduledForDeletion = !!statusData?.plannedDeletionDate; | ||
useEffect(() => setCurrentPassword(''), [deleteStatus, undeleteStatus]); | ||
|
||
if (isScheduledForDeletion) { | ||
const scheduledDate = new Date(statusData.plannedDeletionDate as number); | ||
return ( | ||
<> | ||
<Alert type="critical" className="mb-5"> | ||
{t('Your account is scheduled for deletion on')} {scheduledDate.toLocaleDateString()} | ||
</Alert> | ||
<Section title={t('Cancel delete account')}> | ||
<p className="mb-5 max-w-lg text-slate-400"> | ||
{t('Would you like to cancel the deletion of your account? You can do so until')}{' '} | ||
{scheduledDate.toLocaleDateString()} | ||
</p> | ||
<form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
if (e.currentTarget.reportValidity()) undeleteAccount(currentPassword); | ||
}} | ||
> | ||
<div className="mb-2"> | ||
<Label>{t('Your password')}</Label> | ||
<Input | ||
required | ||
name="currentPassowrd" | ||
id="currentPassowrd" | ||
type="password" | ||
onChange={(e) => setCurrentPassword(e.target.value)} | ||
defaultValue={currentPassword} | ||
autoComplete="current-password" | ||
/> | ||
</div> | ||
<div className="mt-5 flex flex-row-reverse"> | ||
<ActionButton | ||
confirmOptions={{ | ||
title: t('Cancel the deletion of your account'), | ||
body: t('Are you sure you want to cancel the deletion of your account?'), | ||
buttonText: t('Cancel delete account'), | ||
}} | ||
state={undeleteStatus} | ||
isDisabled={!currentPassword} | ||
onClick={() => undeleteAccount(currentPassword)} | ||
> | ||
{t('Cancel delete account')} | ||
</ActionButton> | ||
</div> | ||
</form> | ||
</Section> | ||
</> | ||
); | ||
} else { | ||
return ( | ||
<> | ||
<Section title={t('Delete account')}> | ||
<p className="mb-5 max-w-lg text-slate-400"> | ||
{t( | ||
`If you want to delete you account, you can request account deletion below. | ||
Once requested, you account will be scheduled for deletion after 30 days. | ||
In that time you will be able to cancel the request.` | ||
)} | ||
</p> | ||
<form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
if (e.currentTarget.reportValidity()) deleteAccount(currentPassword); | ||
}} | ||
> | ||
<div className="mb-2"> | ||
<Label>{t('Your password')}</Label> | ||
<Input | ||
required | ||
name="currentPassowrd" | ||
id="currentPassowrd" | ||
type="password" | ||
onChange={(e) => setCurrentPassword(e.target.value)} | ||
defaultValue={currentPassword} | ||
autoComplete="current-password" | ||
/> | ||
</div> | ||
<div className="mt-5 flex flex-row-reverse"> | ||
<ActionButton | ||
confirmOptions={{ | ||
title: t('Delete account'), | ||
body: t('Are you sure you want to delete your account?'), | ||
buttonText: t('Delete account'), | ||
}} | ||
state={deleteStatus} | ||
isDisabled={!currentPassword} | ||
onClick={() => deleteAccount(currentPassword)} | ||
> | ||
{t('Delete account')} | ||
</ActionButton> | ||
</div> | ||
</form> | ||
</Section> | ||
</> | ||
); | ||
} | ||
}; |
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