fix: add product
This commit is contained in:
@@ -6,13 +6,15 @@ import chatReducer from '@/redux-store/slices/chat'
|
||||
import calendarReducer from '@/redux-store/slices/calendar'
|
||||
import kanbanReducer from '@/redux-store/slices/kanban'
|
||||
import emailReducer from '@/redux-store/slices/email'
|
||||
import productReducer from '@/redux-store/slices/product'
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
chatReducer,
|
||||
calendarReducer,
|
||||
kanbanReducer,
|
||||
emailReducer
|
||||
emailReducer,
|
||||
productReducer
|
||||
},
|
||||
middleware: getDefaultMiddleware => getDefaultMiddleware({ serializableCheck: false })
|
||||
})
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Third-party Imports
|
||||
import type { Draft, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { createSlice } from '@reduxjs/toolkit'
|
||||
|
||||
// Type Imports
|
||||
|
||||
// Data Imports
|
||||
import { ProductRequest } from '../../types/services/product'
|
||||
|
||||
const initialState: { productRequest: ProductRequest } = {
|
||||
productRequest: {
|
||||
category_id: '',
|
||||
sku: '',
|
||||
name: '',
|
||||
description: '',
|
||||
barcode: '',
|
||||
price: 0,
|
||||
cost: 0,
|
||||
printer_type: '',
|
||||
image_url: '',
|
||||
variants: []
|
||||
}
|
||||
}
|
||||
|
||||
export const productSlice = createSlice({
|
||||
name: 'product',
|
||||
initialState,
|
||||
reducers: {
|
||||
setProductField: <K extends keyof ProductRequest>(
|
||||
state: Draft<{ productRequest: ProductRequest }>,
|
||||
action: PayloadAction<{ field: K; value: ProductRequest[K] }>
|
||||
) => {
|
||||
const { field, value } = action.payload
|
||||
state.productRequest[field] = value
|
||||
},
|
||||
setProduct: (state, action: PayloadAction<ProductRequest>) => {
|
||||
state.productRequest = action.payload
|
||||
},
|
||||
resetProduct: state => {
|
||||
state.productRequest = initialState.productRequest
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const { setProductField, setProduct, resetProduct } = productSlice.actions
|
||||
|
||||
export default productSlice.reducer
|
||||
Reference in New Issue
Block a user