Advertisement
ikamal7

form.slice.js

Jun 7th, 2023
1,210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // form.slice.js
  2. import { createSlice } from '@reduxjs/toolkit';
  3.  
  4. const initialState = {
  5.     fields: [], // Initialize fields array
  6.     address: '',
  7.     city: '',
  8.     province: '',
  9.     zip: '',
  10.     unit: '',
  11.     propertySize: '',
  12.     footageType: '',
  13.     find: '',
  14.     propertyType: '',
  15.     propertyCondition: '',
  16.     access: '',
  17.     luckBox: '',
  18.     customerCode: '',
  19.     specialRequest: '',
  20.     date: '',
  21.     slot: '',
  22.     firstName: '',
  23.     lastName: '',
  24.     email: '',
  25.     phone: '',
  26. };
  27.  
  28. const formSlice = createSlice({
  29.     name: 'form',
  30.     initialState,
  31.     reducers: {
  32.         updateField(state, action) {
  33.             const { fieldId, value } = action.payload;
  34.             const fieldIndex = state.fields.findIndex((field) => field.id === fieldId);
  35.             if (fieldIndex !== -1) {
  36.                 state.fields[fieldIndex].value = value;
  37.             }
  38.         },
  39.         // Add other reducers as needed
  40.  
  41.     },
  42. });
  43.  
  44. export const { updateField } = formSlice.actions;
  45.  
  46. export default formSlice.reducer;
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement