Codex-Management-Apps / PCBEE-Enterprise-Management-System

Computer Science SAD Thesis Project
0 stars 0 forks source link

Implement State management using zustand #15

Closed khesir closed 3 weeks ago

khesir commented 1 month ago

Implement State mangement to save data for form processing

clicked create service: fetch the latest service id

{
 sales: {
  employee_id: 1,
  total_amount: sales_item.total_amount in total length 
 }
 service: {
    name: service #id
    description: Handled by <employee> in <date>
    status: active;
    has_sales: will be updated when clicked
    has_borrow: will be update when clicked
    has_jo: will be updated when clicked
    has_reservation: will be updated when clicked
 }
 ?borrow: {
 },
 ?reservation: {
 }
 ?sales_item: {
  ...item_data,
  quantity,
  total_amount: price * quantity,
  type: borrow, reservation, joborder
 }
 ?joborder: {
 },
 ?customer: {

 }
}

Ideally use dictionary or hashmap to save all necessary data. Just base Idea here

import {create} from 'zustand';

interface SelectedRowsState {
    selectedDataByType: {
        [key: string]: any[];
    };
    setSelectedData: (type: string, data: any[]) => void;
}

export const useSelectedRowsStore = create<SelectedRowsState>((set) => ({
    selectedDataByType: {},
    setSelectedData: (type, data) =>
        set((state) => ({
            selectedDataByType: {
                ...state.selectedDataByType,
                [type]: data,
            },
        })),
}));
khesir commented 1 month ago

I'll implement this tomorrow