2025-01-24 20:05:48 +01:00
|
|
|
import { LoadingButton } from "@/components/frontend";
|
|
|
|
|
import { GlobalContext } from "@/globalContext";
|
|
|
|
|
import { callCustomAPI } from "@/utils/callCustomAPI";
|
|
|
|
|
import { Dialog, Transition } from "@headlessui/react";
|
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { useContext } from "react";
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import { Fragment } from "react";
|
|
|
|
|
|
2025-07-01 20:44:25 +01:00
|
|
|
export default function TermsAndConditionsModal({
|
|
|
|
|
isOpen,
|
|
|
|
|
closeModal,
|
|
|
|
|
setIsAgreed,
|
|
|
|
|
}) {
|
2025-01-24 20:05:48 +01:00
|
|
|
const [termsAndConditions, setTermsAndCondition] = useState("");
|
|
|
|
|
const [agreed, setAgreed] = useState(false);
|
|
|
|
|
const { dispatch: globalDispatch } = useContext(GlobalContext);
|
|
|
|
|
|
|
|
|
|
async function fetchTermsAndConditions() {
|
|
|
|
|
try {
|
2025-07-01 20:44:25 +01:00
|
|
|
const result = await callCustomAPI(
|
|
|
|
|
"cms",
|
|
|
|
|
"post",
|
|
|
|
|
{ where: [`content_key = 'terms_and_conditions'`], limit: 1, page: 1 },
|
|
|
|
|
"PAGINATE"
|
|
|
|
|
);
|
2025-01-24 20:05:48 +01:00
|
|
|
|
|
|
|
|
if (Array.isArray(result.list) && result.list.length > 0) {
|
|
|
|
|
setTermsAndCondition(result.list[0].content_value);
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
globalDispatch({
|
|
|
|
|
type: "SHOW_ERROR",
|
|
|
|
|
payload: {
|
|
|
|
|
heading: "Cannot get Terms and Conditions",
|
|
|
|
|
message: err.message,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchTermsAndConditions();
|
|
|
|
|
}, []);
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2025-07-01 20:44:25 +01:00
|
|
|
<div
|
|
|
|
|
className={`${
|
|
|
|
|
isOpen ? "flex" : "hidden"
|
|
|
|
|
} fixed inset-0 items-center justify-center`}
|
|
|
|
|
></div>
|
2025-01-24 20:05:48 +01:00
|
|
|
|
2025-07-01 20:44:25 +01:00
|
|
|
<Transition appear show={isOpen} as={Fragment}>
|
|
|
|
|
<Dialog as='div' className='relative z-10' onClose={closeModal}>
|
2025-01-24 20:05:48 +01:00
|
|
|
<Transition.Child
|
|
|
|
|
as={Fragment}
|
2025-07-01 20:44:25 +01:00
|
|
|
enter='ease-out duration-300'
|
|
|
|
|
enterFrom='opacity-0'
|
|
|
|
|
enterTo='opacity-100'
|
|
|
|
|
leave='ease-in duration-200'
|
|
|
|
|
leaveFrom='opacity-100'
|
|
|
|
|
leaveTo='opacity-0'
|
2025-01-24 20:05:48 +01:00
|
|
|
>
|
2025-07-01 20:44:25 +01:00
|
|
|
<div className='fixed inset-0 bg-black bg-opacity-25' />
|
2025-01-24 20:05:48 +01:00
|
|
|
</Transition.Child>
|
|
|
|
|
|
2025-07-01 20:44:25 +01:00
|
|
|
<div className='fixed inset-0 overflow-y-auto'>
|
|
|
|
|
<div className='flex min-h-full items-center justify-center p-4 text-center'>
|
2025-01-24 20:05:48 +01:00
|
|
|
<Transition.Child
|
|
|
|
|
as={Fragment}
|
2025-07-01 20:44:25 +01:00
|
|
|
enter='ease-out duration-300'
|
|
|
|
|
enterFrom='opacity-0 scale-95'
|
|
|
|
|
enterTo='opacity-100 scale-100'
|
|
|
|
|
leave='ease-in duration-200'
|
|
|
|
|
leaveFrom='opacity-100 scale-100'
|
|
|
|
|
leaveTo='opacity-0 scale-95'
|
2025-01-24 20:05:48 +01:00
|
|
|
>
|
2025-07-01 20:44:25 +01:00
|
|
|
<Dialog.Panel className='w-full max-w-6xl transform overflow-hidden rounded-2xl bg-white p-6 text-left align-middle shadow-xl transition-all'>
|
2025-01-24 20:05:48 +01:00
|
|
|
<Dialog.Title
|
2025-07-01 20:44:25 +01:00
|
|
|
as='h3'
|
|
|
|
|
className='text-lg flex items-center justify-between font-medium leading-6 text-gray-900'
|
2025-01-24 20:05:48 +01:00
|
|
|
>
|
|
|
|
|
{" "}
|
|
|
|
|
<button
|
2025-07-01 20:44:25 +01:00
|
|
|
type='button'
|
2025-01-24 20:05:48 +01:00
|
|
|
onClick={closeModal}
|
2025-07-01 20:44:25 +01:00
|
|
|
className='flex justify-end rounded-full border px-3 py-2 text-2xl font-normal duration-100 hover:bg-gray-200 active:bg-gray-300'
|
2025-01-24 20:05:48 +01:00
|
|
|
>
|
|
|
|
|
✕
|
|
|
|
|
</button>
|
|
|
|
|
</Dialog.Title>
|
2025-07-01 20:44:25 +01:00
|
|
|
<div className='mt-2'>
|
2025-01-24 20:05:48 +01:00
|
|
|
<article
|
2025-07-01 20:44:25 +01:00
|
|
|
className='sun-editor-editable my-8 max-h-[600px] overflow-y-auto text-sm'
|
2025-01-24 20:05:48 +01:00
|
|
|
dangerouslySetInnerHTML={{ __html: termsAndConditions }}
|
|
|
|
|
></article>
|
|
|
|
|
</div>
|
2025-07-01 20:44:25 +01:00
|
|
|
<div className='checkbox-container'>
|
2025-01-24 20:05:48 +01:00
|
|
|
<input
|
|
|
|
|
type={"checkbox"}
|
2025-07-01 20:44:25 +01:00
|
|
|
name='i-agree'
|
|
|
|
|
id='i-agree'
|
2025-01-24 20:05:48 +01:00
|
|
|
checked={agreed}
|
2025-07-01 20:44:25 +01:00
|
|
|
onChange={() => {
|
|
|
|
|
setAgreed((prev) => !prev);
|
|
|
|
|
setIsAgreed((prev) => !prev);
|
|
|
|
|
closeModal();
|
|
|
|
|
}}
|
2025-01-24 20:05:48 +01:00
|
|
|
/>
|
|
|
|
|
<label
|
2025-07-01 20:44:25 +01:00
|
|
|
htmlFor='i-agree'
|
|
|
|
|
className='remove-select cursor-pointer items-center'
|
2025-01-24 20:05:48 +01:00
|
|
|
>
|
|
|
|
|
Yeah, I agree to everything
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
</Dialog.Panel>
|
|
|
|
|
</Transition.Child>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</Transition>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|