Skip to content

Commit 4005e61

Browse files
committed
validate geolocation on code input submit
1 parent 5c4529f commit 4005e61

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

apps/app/src/pages/Home/popups/CodePopup/CodePopup.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import CodeInput from '@/components/CodeInput';
44
import Button from '@/components/Button';
55
import { useState } from 'react';
66
import { useCodeApply } from '@/api/code/useCodeApply';
7+
import { useGeoValidation } from '@/hooks/useGeoValidation';
78

89
type CodePopupProps = {
910
isOpen: boolean;
@@ -19,8 +20,16 @@ const CodePopup: React.FC<CodePopupProps> = ({
1920
const [code, setCode] = useState<string[]>(Array(6).fill(''));
2021
const [errorMessage, setErrorMessage] = useState('');
2122
const applyCode = useCodeApply();
23+
const geolocation = useGeoValidation();
2224

2325
function handleCodeSubmit(code: string) {
26+
if (!geolocation.isOk) {
27+
setErrorMessage(
28+
`Ne možete unijeti kod izvan dozvoljene lokacije. ${geolocation?.error ?? ''}`,
29+
);
30+
return;
31+
}
32+
2433
applyCode.mutate(code, {
2534
onSuccess: (submittedCode) => {
2635
closePopup();

0 commit comments

Comments
 (0)