Skip to content

Commit

Permalink
feat: add valueset store
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang committed Oct 1, 2024
1 parent 515bc21 commit ceb77eb
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/state/valueSets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { createSlice, createEntityAdapter, PayloadAction } from '@reduxjs/toolkit'
import { HierarchyElementWithSystem } from 'types'
import { logout } from './me'
import { LabelObject } from 'types/searchCriterias'

type ValueSetOptions = {
id: string
options: HierarchyElementWithSystem[]
}

const valueSetsAdapter = createEntityAdapter<ValueSetOptions>()

const valueSetsSlice = createSlice({
name: 'valueSets',
initialState: valueSetsAdapter.getInitialState({
loading: false,
error: false,
loaded: false,
cache: {} as { [system: string]: LabelObject[] }
}),
reducers: {
addValueSets: valueSetsAdapter.addMany,
updateCache: (state, action: PayloadAction<{ [system: string]: LabelObject[] }>) => {
return {
...state,
cache: action.payload
}
}
},
extraReducers: (builder) => {
builder.addCase(logout.fulfilled, () =>
valueSetsAdapter.getInitialState({ loading: false, error: false, loaded: false, cache: {} })
)
}
})

export const { addValueSets, updateCache } = valueSetsSlice.actions
export default valueSetsSlice.reducer

0 comments on commit ceb77eb

Please sign in to comment.