'use client' import { zodResolver } from '@hookform/resolvers/zod' import { ReactNode, forwardRef, useEffect } from 'react' import { useForm } from 'react-hook-form' import { Alert_Shadcn_, Button, Dialog, DialogContent, DialogSection, DialogSectionSeparator, DialogTitle, FormControl_Shadcn_, FormDescription_Shadcn_, FormField_Shadcn_, FormItem_Shadcn_, FormLabel_Shadcn_, FormMessage_Shadcn_, Form_Shadcn_, Input_Shadcn_, cn, } from 'ui' import { DialogHeader } from 'ui/src/components/shadcn/ui/dialog' import { z } from 'zod' import { Admonition } from './../admonition' export interface TextConfirmModalProps { loading: boolean visible: boolean title: string size?: React.ComponentProps['size'] cancelLabel?: string confirmLabel?: string confirmPlaceholder: string confirmString: string text?: string | ReactNode onConfirm: () => void onCancel: () => void variant?: React.ComponentProps['variant'] alert?: { base?: React.ComponentProps title?: string description?: string } input?: React.ComponentProps label?: React.ComponentProps formMessage?: React.ComponentProps description?: React.ComponentProps blockDeleteButton?: boolean } const TextConfirmModal = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & TextConfirmModalProps >( ( { title, size = 'small', onConfirm, visible, onCancel, loading, cancelLabel = 'Cancel', confirmLabel = 'Submit', confirmPlaceholder, confirmString, alert, input, label, description, formMessage, text, children, blockDeleteButton = true, variant = 'default', ...props }, ref ) => { const formSchema = z.object({ confirmValue: z.literal(confirmString, { required_error: 'Value entered does not match.', }), }) // 1. Define your form. const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { confirmValue: '', }, }) // 2. Define a submit handler. function onSubmit(values: z.infer) { // Do something with the form values. // ✅ This will be type-safe and validated. onConfirm() } useEffect(() => { if (confirmString) form.reset() }, [confirmString]) return ( { if (visible) { onCancel() } }} > {title} {alert && ( )} {children && ( <> {children} )} {/* // older prop from before refactor */} {text !== undefined && ( <>

{text}

)}
( Type{' '} {confirmString} {' '} to confirm. )} />
{!blockDeleteButton && ( )}
) } ) TextConfirmModal.displayName = 'TextConfirmModal' export default TextConfirmModal