Skip to content

Commit

Permalink
add create order form
Browse files Browse the repository at this point in the history
  • Loading branch information
OGreeni committed Apr 16, 2024
1 parent aa58c4f commit 7cc5f37
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions frontend/src/app/orders/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use client';
import { useEffect, useState } from 'react';
import { TextInput } from '@/components/core/TextInput';
import { Button } from '@/components/core/Button';
import { useUserContext } from '@/context/userContext';
import { useRouter } from 'next/navigation';

export default function Page() {
const [clients, setClients] = useState<any[]>([]);
const [clientId, setClientId] = useState('');
const [brand, setBrand] = useState('');
const [weight, setWeight] = useState('');
const { accessToken } = useUserContext();
const router = useRouter();

useEffect(() => {
fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/client/all`, {
credentials: 'include',
headers: {
'cca-auth-token': accessToken,
},
})
.then((res) => res.json())
.then(setClients);
}, [accessToken]);

const onSubmit = () => {
fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/orders`, {
method: 'POST',
credentials: 'include',
headers: {
'cca-auth-token': accessToken,
},
body: JSON.stringify({
client: clientId,
foodItems: { brand, weight },
}),
}).then((res) => {
if (res.ok) {
router.push('/');
}
});
};

return (
<div className="flex flex-col items-center gap-5 p-10">
<div className="flex w-[500px] flex-col items-center gap-5">
<h1 className="text-2xl font-bold">Create an order</h1>
<div className='mt-5 after:ml-0.5 after:text-[red] after:content-["*"]'>
Clients
</div>

<select
onChange={(e) => setClientId(e.target.value)}
className="w-[395px]"
>
{clients.map((client) => {
return (
<option key={client._id} value={client._id}>
{client.name}
</option>
);
})}
</select>
<TextInput
value={brand}
onChange={setBrand}
placeholder={'Brand'}
required
/>
<TextInput
value={weight}
onChange={setWeight}
placeholder={'weight'}
required
/>
<Button text={'Submit'} onClick={onSubmit} />
</div>
</div>
);
}
8 changes: 8 additions & 0 deletions frontend/src/components/core/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export const Navbar: FC = () => {
>
Reports
</Link>
<Link
href="/orders"
className={`transition-colors ${
pathname === '/orders' ? 'text-primary' : ''
}`}
>
Create Order
</Link>
</>
)}
{accountType === 'VOLUNTEER' && (
Expand Down

0 comments on commit 7cc5f37

Please sign in to comment.