-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Goal): allow user to delete goals
- Loading branch information
1 parent
40295f6
commit da13117
Showing
10 changed files
with
292 additions
and
19 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
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,75 @@ | ||
import React, { ChangeEvent, useCallback, useState } from 'react'; | ||
import dynamic from 'next/dynamic'; | ||
import { useTranslations } from 'next-intl'; | ||
|
||
import { dispatchModalEvent, ModalEvent } from '../utils/dispatchModal'; | ||
import { danger0 } from '../design/@generated/themes'; | ||
|
||
import { ModalContent, ModalHeader } from './Modal'; | ||
import { FormTitle } from './FormTitle'; | ||
import { Text } from './Text'; | ||
import { Form } from './Form'; | ||
import { FormInput } from './FormInput'; | ||
import { FormAction, FormActions } from './FormActions'; | ||
import { Button } from './Button'; | ||
|
||
const ModalOnEvent = dynamic(() => import('./ModalOnEvent')); | ||
|
||
interface GoalDeleteModalProps { | ||
id: string; | ||
|
||
onConfirm: () => void; | ||
onCancel?: () => void; | ||
} | ||
|
||
export const GoalDeleteModal: React.FC<GoalDeleteModalProps> = ({ id, onConfirm, onCancel }) => { | ||
const t = useTranslations('GoalDeleteModal'); | ||
|
||
const [deleteConfirmation, setDeleteConfirmation] = useState(''); | ||
|
||
const onConfirmationInputChange = useCallback((e: ChangeEvent<HTMLInputElement>) => { | ||
setDeleteConfirmation(e.currentTarget.value); | ||
}, []); | ||
|
||
const onDeleteCancel = useCallback(() => { | ||
setDeleteConfirmation(''); | ||
onCancel?.(); | ||
dispatchModalEvent(ModalEvent.GoalDeleteModal)(); | ||
}, [onCancel]); | ||
|
||
return ( | ||
<ModalOnEvent view="danger" event={ModalEvent.GoalDeleteModal}> | ||
<ModalHeader> | ||
<FormTitle color={danger0}>{t('You are trying to delete goal')}</FormTitle> | ||
</ModalHeader> | ||
|
||
<ModalContent> | ||
<Text> | ||
{t.rich('To confirm deleting goal please type goal key below', { | ||
goal: () => <b>{id}</b>, | ||
})} | ||
</Text> | ||
|
||
<br /> | ||
|
||
<Form> | ||
<FormInput flat="bottom" placeholder={id} autoComplete="off" onChange={onConfirmationInputChange} /> | ||
|
||
<FormActions flat="top"> | ||
<FormAction left /> | ||
<FormAction right inline> | ||
<Button size="m" text={t('Cancel')} onClick={onDeleteCancel} /> | ||
<Button | ||
size="m" | ||
view="danger" | ||
disabled={deleteConfirmation !== id} | ||
onClick={onConfirm} | ||
text={t('Yes, delete it')} | ||
/> | ||
</FormAction> | ||
</FormActions> | ||
</Form> | ||
</ModalContent> | ||
</ModalOnEvent> | ||
); | ||
}; |
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
Oops, something went wrong.