diff --git a/app/api.ts b/app/api.ts index 602cbac..9c66ac6 100644 --- a/app/api.ts +++ b/app/api.ts @@ -3,6 +3,15 @@ export const fetchCustomerData = async (id: string) => { const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/loota/${id}`, { method: 'GET', }); + + if (response.status === 404) { + return { + identifier: 'Ei löydy', + location: 'Tuntematon', + boxes: [], + } + } + if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } @@ -22,6 +31,7 @@ export const markBoxPickedUp = async (id: string) => { }, body: JSON.stringify({ id: id, pickup_date: new Date().toISOString().split('.')[0] }), }); + if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } diff --git a/app/components/Landing.module.css b/app/components/Landing.module.css index e7d100f..406eaf2 100644 --- a/app/components/Landing.module.css +++ b/app/components/Landing.module.css @@ -24,4 +24,11 @@ border: none; border-radius: 0.5rem; cursor: pointer; +} + +.notFoundMessage { + color: red; + font-weight: bold; + text-align: center; + margin-top: 1rem; } \ No newline at end of file diff --git a/app/components/Landing.tsx b/app/components/Landing.tsx index 99a7d33..578f06a 100644 --- a/app/components/Landing.tsx +++ b/app/components/Landing.tsx @@ -21,12 +21,21 @@ export default function Landing() { } return ( - customerData.identifier === 'Tuntematon' ? ( -
- - - -
) : ( + customerData.identifier === 'Tuntematon' || customerData.identifier === 'Ei löydy' ? ( + <> +
+ + + +
+ + {customerData.identifier === 'Ei löydy' && ( +
+ Tunnusta ei löydy. Ole hyvä ja tarkista tunnus. +
+ )} + + ) : ( ) );