|
| 1 | +import { useLocalize } from '~/hooks'; |
| 2 | +import { OGDialog } from '~/components/ui'; |
| 3 | +import DialogTemplate from '~/components/ui/DialogTemplate'; |
| 4 | +import { useAuthContext } from '~/hooks'; |
| 5 | +import Markdown from '~/components/Chat/Messages/Content/Markdown'; |
| 6 | +import { useToastContext } from '~/Providers'; |
| 7 | +import { useAcceptTermsMutation } from '~/data-provider'; |
| 8 | + |
| 9 | +const TermsAndConditionsModal = ({ |
| 10 | + open, |
| 11 | + onOpenChange, |
| 12 | + onAccept, |
| 13 | + onDecline, |
| 14 | + title, |
| 15 | + modalContent, |
| 16 | +}: { |
| 17 | + open: boolean; |
| 18 | + onOpenChange: (isOpen: boolean) => void; |
| 19 | + onAccept: () => void; |
| 20 | + onDecline: () => void; |
| 21 | + title?: string; |
| 22 | + contentUrl?: string; |
| 23 | + modalContent?: string; |
| 24 | +}) => { |
| 25 | + const localize = useLocalize(); |
| 26 | + const { showToast } = useToastContext(); |
| 27 | + const acceptTermsMutation = useAcceptTermsMutation({ |
| 28 | + onSuccess: () => { |
| 29 | + onAccept(); |
| 30 | + onOpenChange(false); |
| 31 | + }, |
| 32 | + onError: () => { |
| 33 | + showToast({ message: 'Failed to accept terms' }); |
| 34 | + }, |
| 35 | + }); |
| 36 | + |
| 37 | + const handleAccept = () => { |
| 38 | + acceptTermsMutation.mutate(); |
| 39 | + }; |
| 40 | + |
| 41 | + const handleDecline = () => { |
| 42 | + onDecline(); |
| 43 | + onOpenChange(false); |
| 44 | + }; |
| 45 | + |
| 46 | + const handleOpenChange = (isOpen: boolean) => { |
| 47 | + if (open && !isOpen) { |
| 48 | + return; |
| 49 | + } |
| 50 | + onOpenChange(isOpen); |
| 51 | + }; |
| 52 | + |
| 53 | + return ( |
| 54 | + <OGDialog open={open} onOpenChange={handleOpenChange}> |
| 55 | + <DialogTemplate |
| 56 | + title={title ?? localize('com_ui_terms_and_conditions')} |
| 57 | + className="w-11/12 max-w-3xl sm:w-3/4 md:w-1/2 lg:w-2/5" |
| 58 | + showCloseButton={false} |
| 59 | + showCancelButton={false} |
| 60 | + main={ |
| 61 | + <div className="max-h-[60vh] overflow-y-auto p-4"> |
| 62 | + <div className="prose dark:prose-invert w-full max-w-none !text-black dark:!text-white"> |
| 63 | + {modalContent ? ( |
| 64 | + <Markdown content={modalContent} isLatestMessage={false} /> |
| 65 | + ) : ( |
| 66 | + <p>{localize('com_ui_no_terms_content')}</p> |
| 67 | + )} |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + } |
| 71 | + buttons={ |
| 72 | + <> |
| 73 | + <button |
| 74 | + onClick={handleDecline} |
| 75 | + className="border-border-none bg-surface-500 dark:hover:bg-surface-600 inline-flex h-10 items-center justify-center rounded-lg px-4 py-2 text-sm text-white hover:bg-gray-600" |
| 76 | + > |
| 77 | + {localize('com_ui_decline')} |
| 78 | + </button> |
| 79 | + <button |
| 80 | + onClick={handleAccept} |
| 81 | + className="border-border-none bg-surface-500 inline-flex h-10 items-center justify-center rounded-lg px-4 py-2 text-sm text-white hover:bg-green-600 dark:hover:bg-green-600" |
| 82 | + > |
| 83 | + {localize('com_ui_accept')} |
| 84 | + </button> |
| 85 | + </> |
| 86 | + } |
| 87 | + /> |
| 88 | + </OGDialog> |
| 89 | + ); |
| 90 | +}; |
| 91 | + |
| 92 | +export default TermsAndConditionsModal; |
0 commit comments