Skip to content

Commit

Permalink
add delivery location dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
OGreeni committed May 22, 2024
1 parent 1c983c6 commit fcd5bf2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .idea/workspace.xml

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

36 changes: 30 additions & 6 deletions frontend/src/app/client-form/Client.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { useUserContext } from '@/context/userContext';
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { Button } from '@/components/core/Button';
import { TextInput } from '@/components/core/TextInput';
Expand Down Expand Up @@ -30,6 +31,23 @@ interface ClientProps {

function Client(props: ClientProps) {
const [isError, setIsError] = useState(false);
const [siteLocations, setSiteLocations] = useState<any[]>([]);

const { accessToken } = useUserContext();

useEffect(() => {
fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/site/all`, {
credentials: 'include',
headers: {
'cca-auth-token': accessToken,
},
})
.then((res) => res.json())
.then((sites) => {
setSiteLocations(sites);
props.setSite(sites[0].location);
});
}, [accessToken, props]);

return (
<form className="">
Expand Down Expand Up @@ -57,12 +75,18 @@ function Client(props: ClientProps) {
<div className='mt-5 after:ml-0.5 after:text-[red] after:content-["*"]'>
Delivery Site Location
</div>
<TextInput
value={props.site || ''}
placeholder={''}
onChange={props.setSite}
required
/>
<select
onChange={(e) => props.setSite(e.target.value)}
className="w-[395px]"
>
{siteLocations.map((location) => {
return (
<option key={location._id} value={location._id}>
{location.location}
</option>
);
})}
</select>

<div className='mt-5 after:ml-0.5 after:text-[red] after:content-["*"]'>
Street Address
Expand Down

0 comments on commit fcd5bf2

Please sign in to comment.