1 |
9c55d3bb
|
Schwobik
|
import { createSlice } from "@reduxjs/toolkit"
|
2 |
|
|
import { Artist, Inventory, Room } from "../../types/searchFormTypes"
|
3 |
|
|
import {
|
4 |
|
|
fetchArtists, fetchCities,
|
5 |
|
|
fetchCountries,
|
6 |
|
|
fetchInstitutions,
|
7 |
|
|
fetchInventories,
|
8 |
|
|
fetchNationalities, fetchPlans, fetchSubjects, fetchTechniques
|
9 |
|
|
} from "../actions/searchFormThunks"
|
10 |
|
|
|
11 |
|
|
export interface SearchFormState {
|
12 |
|
|
inventories: Inventory[]
|
13 |
|
|
rooms: Room[]
|
14 |
|
|
artists: Artist[]
|
15 |
|
|
nationalities: string[]
|
16 |
|
|
techniques: string[]
|
17 |
|
|
institutions: string[]
|
18 |
|
|
countries: string[]
|
19 |
|
|
cities: string[]
|
20 |
|
|
subjects: string[]
|
21 |
|
|
lastError?: string
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
const initialState: SearchFormState = {
|
25 |
|
|
inventories: [],
|
26 |
|
|
rooms: [],
|
27 |
|
|
artists: [],
|
28 |
|
|
nationalities: [],
|
29 |
|
|
techniques: [],
|
30 |
|
|
institutions: [],
|
31 |
|
|
countries: [],
|
32 |
|
|
cities: [],
|
33 |
|
|
subjects: [],
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
export const searchFormSlice = createSlice({
|
37 |
|
|
name: "searchForm",
|
38 |
|
|
initialState: initialState,
|
39 |
|
|
reducers: {
|
40 |
|
|
resetSearchForm: () => initialState,
|
41 |
|
|
setInventories: (state, action) => {
|
42 |
|
|
state.inventories = action.payload
|
43 |
|
|
},
|
44 |
|
|
setRooms: (state, action) => {
|
45 |
|
|
state.rooms = action.payload
|
46 |
|
|
},
|
47 |
|
|
setArtists: (state, action) => {
|
48 |
|
|
state.artists = action.payload
|
49 |
|
|
},
|
50 |
|
|
setNationalities: (state, action) => {
|
51 |
|
|
state.nationalities = action.payload
|
52 |
|
|
},
|
53 |
|
|
},
|
54 |
|
|
extraReducers: (builder) => {
|
55 |
|
|
// ------------ Inventories ------------
|
56 |
|
|
builder.addCase(fetchInventories.fulfilled, (state, action) => {
|
57 |
|
|
state.inventories = action.payload
|
58 |
|
|
state.lastError = ""
|
59 |
|
|
})
|
60 |
|
|
builder.addCase(fetchInventories.rejected, (state, action) => {
|
61 |
|
|
state.lastError = action.error.message
|
62 |
|
|
})
|
63 |
|
|
|
64 |
|
|
// ------------ Institutions ------------
|
65 |
|
|
builder.addCase(fetchInstitutions.fulfilled, (state, action) => {
|
66 |
|
|
state.institutions = action.payload
|
67 |
|
|
state.lastError = ""
|
68 |
|
|
})
|
69 |
|
|
builder.addCase(fetchInstitutions.rejected, (state, action) => {
|
70 |
|
|
state.lastError = action.error.message
|
71 |
|
|
})
|
72 |
|
|
|
73 |
|
|
// ------------ Nationalities ------------
|
74 |
|
|
builder.addCase(fetchNationalities.fulfilled, (state, action) => {
|
75 |
|
|
state.nationalities = action.payload
|
76 |
|
|
state.lastError = ""
|
77 |
|
|
})
|
78 |
|
|
builder.addCase(fetchNationalities.rejected, (state, action) => {
|
79 |
|
|
state.lastError = action.error.message
|
80 |
|
|
})
|
81 |
|
|
|
82 |
|
|
// ------------ Countries ------------
|
83 |
|
|
builder.addCase(fetchCountries.fulfilled, (state, action) => {
|
84 |
|
|
state.countries = action.payload
|
85 |
|
|
state.lastError = ""
|
86 |
|
|
})
|
87 |
|
|
builder.addCase(fetchCountries.rejected, (state, action) => {
|
88 |
|
|
state.lastError = action.error.message
|
89 |
|
|
})
|
90 |
|
|
|
91 |
|
|
// ------------ Artists ------------
|
92 |
|
|
builder.addCase(fetchArtists.fulfilled, (state, action) => {
|
93 |
|
|
state.artists = action.payload
|
94 |
|
|
state.lastError = ""
|
95 |
|
|
})
|
96 |
|
|
builder.addCase(fetchArtists.rejected, (state, action) => {
|
97 |
|
|
state.lastError = action.error.message
|
98 |
|
|
})
|
99 |
|
|
|
100 |
|
|
// ------------ Rooms ------------
|
101 |
|
|
builder.addCase(fetchPlans.fulfilled, (state, action) => {
|
102 |
|
|
state.rooms = action.payload
|
103 |
|
|
state.lastError = ""
|
104 |
|
|
})
|
105 |
|
|
builder.addCase(fetchPlans.rejected, (state, action) => {
|
106 |
|
|
state.lastError = action.error.message
|
107 |
|
|
})
|
108 |
|
|
|
109 |
|
|
// ------------ Subjects ------------
|
110 |
|
|
builder.addCase(fetchSubjects.fulfilled, (state, action) => {
|
111 |
|
|
state.subjects = action.payload
|
112 |
|
|
state.lastError = ""
|
113 |
|
|
})
|
114 |
|
|
builder.addCase(fetchSubjects.rejected, (state, action) => {
|
115 |
|
|
state.lastError = action.error.message
|
116 |
|
|
})
|
117 |
|
|
|
118 |
|
|
// ------------ Cities ------------
|
119 |
|
|
builder.addCase(fetchCities.fulfilled, (state, action) => {
|
120 |
|
|
state.cities = action.payload
|
121 |
|
|
state.lastError = ""
|
122 |
|
|
})
|
123 |
|
|
builder.addCase(fetchCities.rejected, (state, action) => {
|
124 |
|
|
state.lastError = action.error.message
|
125 |
|
|
})
|
126 |
|
|
|
127 |
|
|
// ------------ Techniques ------------
|
128 |
|
|
builder.addCase(fetchTechniques.fulfilled, (state, action) => {
|
129 |
|
|
state.techniques = action.payload
|
130 |
|
|
state.lastError = ""
|
131 |
|
|
})
|
132 |
|
|
builder.addCase(fetchTechniques.rejected, (state, action) => {
|
133 |
|
|
state.lastError = action.error.message
|
134 |
|
|
})
|
135 |
|
|
}
|
136 |
|
|
})
|
137 |
|
|
|
138 |
|
|
export const { resetSearchForm, setInventories, setRooms, setArtists, setNationalities } = searchFormSlice.actions
|
139 |
|
|
|
140 |
|
|
export default searchFormSlice.reducer
|