diff --git a/resources/js/Pages/Customer.tsx b/resources/js/Pages/Customer.tsx new file mode 100644 index 0000000..e234325 --- /dev/null +++ b/resources/js/Pages/Customer.tsx @@ -0,0 +1,138 @@ +import TextInput from '@/Components/TextInput'; +import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; +import { Head, useForm } from '@inertiajs/react'; +import { FormEventHandler } from 'react'; + +interface CustomerProps { + customer:{ + id: number + name: string + deposit: number + amount_left: number + give_leftover: number + purchases: [{ + id: number + amount: number + }] + } +}; + +export default function Customer({customer}: CustomerProps) { + + const { data, setData, post, processing, errors, reset } = useForm({ + amount: "", + customer_id: customer.id, + deposit: "", + id: customer.id + + }); + + const submit: FormEventHandler = (e) => { + e.preventDefault() + post(route('register_purchase'), { + onFinish: () => reset('amount'), + }); + } + + const submitDeposit: FormEventHandler = (e) => { + e.preventDefault() + post('/api/register_deposit/' + customer.id, { + onFinish: () => reset('deposit'), + }); + } + + return ( + + + + + + {customer.name} + + + Saldo: {customer.amount_left ? customer.amount_left : 0} kr + { customer.deposit && + Swishad summa: {customer.deposit} kr + } + Ge ev överblivet saldo till vBytes: {customer.give_leftover ? "Ja" : "Nej"} + + + + Registrera köp + + + + setData('amount', e.target.value)} + /> + + + + + Spara + + + + + + + Lägga in swishpeng + + + + setData('deposit', e.target.value)} + /> + + + + + Spara + + + + + + + + Tidigare köp + + + + + + + {customer.purchases && customer.purchases.map( purchase => { + return + {purchase.amount} kr + + })} + + + + + + + + + + + + + + ); +}
Swishad summa: {customer.deposit} kr
Ge ev överblivet saldo till vBytes: {customer.give_leftover ? "Ja" : "Nej"}
{purchase.amount} kr