@@ -5,11 +5,20 @@ import { useSWRConfig } from "swr/_internal";
55
66import { Inventory_Details_Interface } from "@/components/ui/card_organization_inventory_details_modal" ;
77import Header from "@/components/ui/navbar_organization" ;
8+ import { formatDateForInput } from "@/helpers/helper_functions" ;
89import { BASE_URL } from "@/hooks/organization_call_backend" ;
910import { createNewItemClean } from "@/hooks/organization_clean_backend_calls" ;
1011// import { createItem } from '../hooks/organization_call_backend';
1112
1213const Organization_Add_Product = ( ) => {
14+ // get the query from the other buttons
15+ const { mode, data } = useRouter ( ) . query ;
16+
17+ // covnert the data back from json
18+ const parsedData : Inventory_Details_Interface | null = data
19+ ? JSON . parse ( data as string )
20+ : null ;
21+
1322 // it creates a page stack that we can use to navigate
1423 // when to use and should we replace all href with router.push?
1524 // we only use this when we want to have buttons that go back to certain pages or after finishing a task
@@ -24,21 +33,24 @@ const Organization_Add_Product = () => {
2433 > ( {
2534 // id is excluded because it will be auto generated by backend
2635 // id: number,
27- name : "" ,
28- details : "" ,
29- categories : "" ,
30- availability : "" ,
36+ name : mode === "add" ? "" : parsedData ?. name ,
37+ details : mode === "add" ? "" : parsedData ?. details ,
38+ categories : mode === "add" ? "" : parsedData ?. categories ,
39+ availability : mode === "add" ? "" : parsedData ?. availability ,
3140
3241 // organization is kept away because we will fix it to the name of the organization that is logged in
3342 // organization: "",
3443
35- collectionPoint : "" ,
36- borrowerName : "" ,
37- borrowedOn : "" ,
38- returnedOn : "" ,
39- dueOn : "" ,
40- expiryDate : "" ,
41- dateAdded : "" ,
44+ collectionPoint : mode === "add" ? "" : parsedData ?. collectionPoint ,
45+ borrowerName : mode === "add" ? "" : parsedData ?. borrowerName ,
46+ borrowedOn :
47+ mode === "add" ? "" : formatDateForInput ( parsedData ?. borrowedOn ) ,
48+ returnedOn :
49+ mode === "add" ? "" : formatDateForInput ( parsedData ?. returnedOn ) ,
50+ dueOn : mode === "add" ? "" : formatDateForInput ( parsedData ?. dueOn ) ,
51+ expiryDate :
52+ mode === "add" ? "" : formatDateForInput ( parsedData ?. expiryDate ) ,
53+ dateAdded : mode === "add" ? "" : formatDateForInput ( parsedData ?. dateAdded ) ,
4254 } ) ;
4355
4456 // used whenever you type in the form fields
0 commit comments