forked from d3i-infra/data-donation-task
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfirm.tsx
45 lines (38 loc) · 1.27 KB
/
confirm.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Weak } from '../../../../helpers'
import { ReactFactoryContext } from '../../factory'
import { PropsUIPromptConfirm } from '../../../../types/prompts'
import { Translator } from '../../../../translator'
import { BodyLarge } from '../elements/text'
import { PrimaryButton } from '../elements/button'
type Props = Weak<PropsUIPromptConfirm> & ReactFactoryContext
export const Confirm = (props: Props): JSX.Element => {
const { resolve } = props
const { text, ok, cancel } = prepareCopy(props)
function handleOk (): void {
resolve?.({ __type__: 'PayloadTrue', value: true })
}
function handleCancel (): void {
resolve?.({ __type__: 'PayloadFalse', value: false })
}
return (
<>
<BodyLarge text={text} margin='mb-4' />
<div className='flex flex-row gap-4'>
<PrimaryButton label={ok} onClick={handleOk} color='text-grey1 bg-tertiary' />
<PrimaryButton label={cancel} onClick={handleCancel} color='text-white bg-primary' />
</div>
</>
)
}
interface Copy {
text: string
ok: string
cancel: string
}
function prepareCopy ({ text, ok, cancel, locale }: Props): Copy {
return {
text: Translator.translate(text, locale),
ok: Translator.translate(ok, locale),
cancel: Translator.translate(cancel, locale)
}
}