Skip to content

Commit bd4bf03

Browse files
committed
integrated add new contractor
1 parent 2bcad63 commit bd4bf03

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

client/components/modals/ContractorControl/AddNewContractor.tsx

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@ import {
1212

1313
import { Input } from "@/components/ui/input";
1414
import { Label } from "@/components/ui/label";
15-
import React, { useState } from "react";
15+
import React, { useEffect, useState } from "react";
1616
import SetZone from "../../maps/SetZone";
1717
import useCreateSTS, { STS } from "@/hooks/entityCreation/useCreateSTS";
1818
import { message } from "antd";
1919
import { Contractor } from "@/data/roles";
2020
import useCreateContractor from "@/hooks/entityCreation/useCreateContractor";
21+
import useGetAllSTS from "@/hooks/stsdata/useGetAllSTS";
22+
import {
23+
Select,
24+
SelectContent,
25+
SelectGroup,
26+
SelectItem,
27+
SelectLabel,
28+
SelectTrigger,
29+
SelectValue,
30+
} from "@/components/ui/select";
2131

2232
interface DialogWrapperProps {
2333
children: React.ReactNode;
@@ -33,11 +43,14 @@ export const AddNewContractor: React.FC<DialogWrapperProps> = ({
3343
const [workforceSize, setWorkForceSize] = useState(0);
3444
const [paymentPerTon, setPaymentPerTon] = useState(0);
3545
const [requiredWastePerDay, setRequiredWastePerDay] = useState(0);
36-
const [contractDuration, setContractDuration] = useState(0);
46+
const [contractDuration, setContractDuration] = useState("");
3747
const [area, setArea] = useState("");
38-
const [assignedSTS, setAssignedSTS] = useState("");
48+
const [stsId, setStsId] = useState("");
3949
const { createContractor } = useCreateContractor();
4050

51+
const { stsList } = useGetAllSTS();
52+
useEffect(() => {}, [stsList]);
53+
4154
const handleSaveChanges = async () => {
4255
const data: Contractor = {
4356
name,
@@ -49,7 +62,7 @@ export const AddNewContractor: React.FC<DialogWrapperProps> = ({
4962
requiredWastePerDay,
5063
contractDuration,
5164
area,
52-
assignedSTS,
65+
stsId,
5366
};
5467

5568
console.log(data);
@@ -164,10 +177,9 @@ export const AddNewContractor: React.FC<DialogWrapperProps> = ({
164177
<Input
165178
id="workforceSize"
166179
placeholder="Add Workforcesize here"
167-
className="col-span-3"
168-
type="number"
180+
className="col-span-3"
169181
value={contractDuration}
170-
onChange={(e) => setContractDuration(parseInt(e.target.value))}
182+
onChange={(e) => setContractDuration(e.target.value)}
171183
/>
172184
</div>
173185
<div className="grid grid-cols-4 items-center gap-4">
@@ -183,16 +195,30 @@ export const AddNewContractor: React.FC<DialogWrapperProps> = ({
183195
/>
184196
</div>
185197
<div className="grid grid-cols-4 items-center gap-4">
186-
<Label htmlFor="assignedSTS" className="text-right">
198+
<Label htmlFor="assignedSTS" className="text-right ">
187199
Assigned STS
188200
</Label>
189-
<Input
190-
id="assignedSTS"
191-
placeholder="Add Workforcesize here"
192-
className="col-span-3"
193-
value={assignedSTS}
194-
onChange={(e) => setAssignedSTS(e.target.value)}
195-
/>
201+
<Select
202+
value={stsId}
203+
onValueChange={(e) => setStsId(e)}
204+
>
205+
<SelectTrigger className="col-span-3">
206+
<SelectValue
207+
id="assignedSTS"
208+
placeholder="Select assigned STS from the list"
209+
/>
210+
</SelectTrigger>
211+
<SelectContent>
212+
<SelectGroup>
213+
<SelectLabel>STS</SelectLabel>
214+
{stsList.map((sts, index: number) => (
215+
<SelectItem key={index} value={sts.id}>
216+
{sts.name}
217+
</SelectItem>
218+
))}
219+
</SelectGroup>
220+
</SelectContent>
221+
</Select>
196222
</div>
197223
</div>
198224
<DialogFooter>

client/data/apiRoutes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export const apiRoutes = {
3030
},
3131
},
3232
contractor: {
33-
create: `${baseUrl}/contracts/create`,
34-
getAll: `${baseUrl}/contracts`,
35-
delete: `${baseUrl}/contracts/`,
36-
edit: `${baseUrl}/contracts/`,
33+
create: `${baseUrl}/contractors/create`,
34+
getAll: `${baseUrl}/contractors`,
35+
delete: `${baseUrl}/contractors/`,
36+
edit: `${baseUrl}/contractors/`,
3737
},
3838
landfill: {
3939
getbyId: `${baseUrl}/landfills/`,

client/data/roles.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export type Contractor = {
2525
workforceSize: number;
2626
paymentPerTon: number;
2727
requiredWastePerDay: number;
28-
contractDuration: number;
28+
contractDuration: string;
2929
area: string;
30-
assignedSTS: string;
30+
stsId: string;
3131
manager?: ContractorManager;
3232
};

client/hooks/entityCreation/useCreateContractor.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export default function useCreateContractor() {
1414
return (
1515
contractorData.name.length > 0 &&
1616
contractorData.contactNumber.length > 0 &&
17-
contractorData.contactNumber.length > 0 &&
1817
contractorData.tinNumber.length !== null
1918
);
2019
}

0 commit comments

Comments
 (0)