react-garden
Version:
React + TypeScript + ThreeJS app using Material UI on NextJS, Apollo Client, GraphQL + WordPress REST APIs, for ThreeD web development.. a part of the threed.ai code family.
44 lines (36 loc) • 1.08 kB
JavaScript
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
// ** Axios Imports
import axios from 'axios'
// ** Fetch Invoices
export const fetchData = createAsyncThunk('appInvoice/fetchData', async params => {
const response = await axios.get('/apps/invoice/invoices', {
params
})
return response.data
})
export const deleteInvoice = createAsyncThunk('appInvoice/deleteData', async (id, { getState, dispatch }) => {
const response = await axios.delete('/apps/invoice/delete', {
data: id
})
await dispatch(fetchData(getState().invoice.params))
return response.data
})
export const appInvoiceSlice = createSlice({
name: 'appInvoice',
initialState: {
data: [],
total: 1,
params: {},
allData: []
},
reducers: {},
extraReducers: builder => {
builder.addCase(fetchData.fulfilled, (state, action) => {
state.data = action.payload.invoices
state.params = action.payload.params
state.allData = action.payload.allData
state.total = action.payload.total
})
}
})
export default appInvoiceSlice.reducer