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
46
47
48
49
50
51
52
53
54
55
|
import {
Button,
Form,
FormButtons,
FormField,
FormSubmitButton,
TextField,
} from '@umami/react-zen';
import { useMessages } from '@/components/hooks';
export function TypeConfirmationForm({
confirmationValue,
buttonLabel,
buttonVariant,
isLoading,
error,
onConfirm,
onClose,
}: {
confirmationValue: string;
buttonLabel?: string;
buttonVariant?: 'primary' | 'outline' | 'quiet' | 'danger' | 'zero';
isLoading?: boolean;
error?: string | Error;
onConfirm?: () => void;
onClose?: () => void;
}) {
const { formatMessage, labels, messages, getErrorMessage } = useMessages();
if (!confirmationValue) {
return null;
}
return (
<Form onSubmit={onConfirm} error={getErrorMessage(error)}>
<p>
{formatMessage(messages.actionConfirmation, {
confirmation: confirmationValue,
})}
</p>
<FormField
label={formatMessage(labels.confirm)}
name="confirm"
rules={{ validate: value => value === confirmationValue }}
>
<TextField autoComplete="off" />
</FormField>
<FormButtons>
<Button onPress={onClose}>{formatMessage(labels.cancel)}</Button>
<FormSubmitButton isLoading={isLoading} variant={buttonVariant}>
{buttonLabel || formatMessage(labels.ok)}
</FormSubmitButton>
</FormButtons>
</Form>
);
}
|