mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-12 10:34:20 +02:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
|
|
|
import { StateRequest, elementAddFetch } from "./utils"
|
|
import { Postulant } from "../services/postulants"
|
|
import { postulantAdd } from "../services/postulantsAccessors"
|
|
|
|
const postulantAdapter = createEntityAdapter<Postulant>()
|
|
|
|
const postulantAddSlice = createSlice({
|
|
name: "postulantAdd",
|
|
initialState: postulantAdapter.getInitialState({
|
|
readyStatus: "idle",
|
|
} as StateRequest),
|
|
reducers: {
|
|
getRequesting: (state) => {
|
|
state.readyStatus = "request"
|
|
},
|
|
getSuccess: (state, { payload }: PayloadAction<Postulant>) => {
|
|
state.readyStatus = "success"
|
|
postulantAdapter.setOne(state, payload)
|
|
},
|
|
getFailure: (state, { payload }: PayloadAction<string>) => {
|
|
state.readyStatus = "failure"
|
|
state.error = payload
|
|
},
|
|
},
|
|
})
|
|
|
|
export default postulantAddSlice.reducer
|
|
export const { getRequesting, getSuccess, getFailure } = postulantAddSlice.actions
|
|
|
|
export const fetchPostulantAdd = elementAddFetch(
|
|
postulantAdd,
|
|
getRequesting,
|
|
getSuccess,
|
|
getFailure,
|
|
() => null,
|
|
() => null
|
|
)
|