import { useCallback, useRef, useState } from 'react';
import { useMessages, useNavigation } from '@ollie-shop/sdk';
import styles from './styles.module.css';
export default function TermsGate() {
const [accepted, setAccepted] = useState(false);
const acceptedRef = useRef(accepted);
acceptedRef.current = accepted;
const { addMessage } = useMessages();
const validator = useCallback(() => {
if (acceptedRef.current) return true;
addMessage({ type: 'error', content: 'Please accept the terms to continue.' });
return false;
}, [addMessage]);
useNavigation(validator);
return (
<label className={styles.gate}>
<input
type="checkbox"
checked={accepted}
onChange={(event) => setAccepted(event.target.checked)}
/>
I accept the terms and conditions
</label>
);
}