1 |
9c55d3bb
|
Schwobik
|
import { createAsyncThunk } from "@reduxjs/toolkit"
|
2 |
|
|
import {
|
3 |
|
|
fetchArtistNamesRequest,
|
4 |
|
|
fetchCitiesRequest,
|
5 |
|
|
fetchCountriesRequest,
|
6 |
|
|
fetchInstitutionsRequest,
|
7 |
|
|
fetchInventoriesRequest,
|
8 |
|
|
fetchNationalitiesRequest,
|
9 |
|
|
fetchPlanRequest,
|
10 |
|
|
fetchSubjectsRequest,
|
11 |
|
|
fetchTechniquesRequest
|
12 |
|
|
} from "../../api/searchFormService"
|
13 |
|
|
|
14 |
|
|
export const fetchInventories = createAsyncThunk(
|
15 |
|
|
"searchForm/fetchInventories",
|
16 |
|
|
async () => {
|
17 |
|
|
try {
|
18 |
|
|
const response = await fetchInventoriesRequest()
|
19 |
|
|
if (response.status === 200) {
|
20 |
|
|
return response.data
|
21 |
|
|
} else {
|
22 |
|
|
return Promise.reject(response.data ? response.data : "Fetch inventories failed")
|
23 |
|
|
}
|
24 |
|
|
} catch (err: any) {
|
25 |
|
|
return Promise.reject(err.response.data)
|
26 |
|
|
}
|
27 |
|
|
}
|
28 |
|
|
)
|
29 |
|
|
|
30 |
|
|
export const fetchCountries = createAsyncThunk(
|
31 |
|
|
"searchForm/fetchCountries",
|
32 |
|
|
async () => {
|
33 |
|
|
try {
|
34 |
|
|
const response = await fetchCountriesRequest()
|
35 |
|
|
if (response.status === 200) {
|
36 |
|
|
return response.data
|
37 |
|
|
} else {
|
38 |
|
|
return Promise.reject(response.data ? response.data : "Fetch countries failed")
|
39 |
|
|
}
|
40 |
|
|
} catch (err: any) {
|
41 |
|
|
return Promise.reject(err.response.data)
|
42 |
|
|
}
|
43 |
|
|
}
|
44 |
|
|
)
|
45 |
|
|
|
46 |
|
|
export const fetchInstitutions = createAsyncThunk(
|
47 |
|
|
"searchForm/fetchInstitutions",
|
48 |
|
|
async () => {
|
49 |
|
|
try {
|
50 |
|
|
const response = await fetchInstitutionsRequest()
|
51 |
|
|
if (response.status === 200) {
|
52 |
|
|
return response.data
|
53 |
|
|
} else {
|
54 |
|
|
return Promise.reject(response.data ? response.data : "Fetch institutions failed")
|
55 |
|
|
}
|
56 |
|
|
} catch (err: any) {
|
57 |
|
|
return Promise.reject(err.response.data)
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
)
|
61 |
|
|
|
62 |
|
|
export const fetchArtists = createAsyncThunk(
|
63 |
|
|
"searchForm/fetchArtists",
|
64 |
|
|
async () => {
|
65 |
|
|
try {
|
66 |
|
|
const response = await fetchArtistNamesRequest()
|
67 |
|
|
if (response.status === 200) {
|
68 |
|
|
return response.data
|
69 |
|
|
} else {
|
70 |
|
|
return Promise.reject(response.data ? response.data : "Fetch artists failed")
|
71 |
|
|
}
|
72 |
|
|
} catch (err: any) {
|
73 |
|
|
return Promise.reject(err.response.data)
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
)
|
77 |
|
|
|
78 |
|
|
export const fetchTechniques = createAsyncThunk(
|
79 |
|
|
"searchForm/fetchTechniques",
|
80 |
|
|
async () => {
|
81 |
|
|
try {
|
82 |
|
|
const response = await fetchTechniquesRequest()
|
83 |
|
|
if (response.status === 200) {
|
84 |
|
|
return response.data
|
85 |
|
|
} else {
|
86 |
|
|
return Promise.reject(response.data ? response.data : "Fetch techniques failed")
|
87 |
|
|
}
|
88 |
|
|
} catch (err: any) {
|
89 |
|
|
return Promise.reject(err.response.data)
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
)
|
93 |
|
|
|
94 |
|
|
export const fetchNationalities = createAsyncThunk(
|
95 |
|
|
"searchForm/fetchNationalities",
|
96 |
|
|
async () => {
|
97 |
|
|
try {
|
98 |
|
|
const response = await fetchNationalitiesRequest()
|
99 |
|
|
if (response.status === 200) {
|
100 |
|
|
return response.data
|
101 |
|
|
} else {
|
102 |
|
|
return Promise.reject(response.data ? response.data : "Fetch nationalities failed")
|
103 |
|
|
}
|
104 |
|
|
} catch (err: any) {
|
105 |
|
|
return Promise.reject(err.response.data)
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
)
|
109 |
|
|
|
110 |
|
|
export const fetchCities = createAsyncThunk(
|
111 |
|
|
"searchForm/fetchCities",
|
112 |
|
|
async () => {
|
113 |
|
|
try {
|
114 |
|
|
const response = await fetchCitiesRequest()
|
115 |
|
|
if (response.status === 200) {
|
116 |
|
|
return response.data
|
117 |
|
|
} else {
|
118 |
|
|
return Promise.reject(response.data ? response.data : "Fetch cities failed")
|
119 |
|
|
}
|
120 |
|
|
} catch (err: any) {
|
121 |
|
|
return Promise.reject(err.response.data)
|
122 |
|
|
}
|
123 |
|
|
}
|
124 |
|
|
)
|
125 |
|
|
|
126 |
|
|
export const fetchSubjects = createAsyncThunk(
|
127 |
|
|
"searchForm/fetchSubjects",
|
128 |
|
|
async () => {
|
129 |
|
|
try {
|
130 |
|
|
const response = await fetchSubjectsRequest()
|
131 |
|
|
if (response.status === 200) {
|
132 |
|
|
return response.data
|
133 |
|
|
} else {
|
134 |
|
|
return Promise.reject(response.data ? response.data : "Fetch subjects failed")
|
135 |
|
|
}
|
136 |
|
|
} catch (err: any) {
|
137 |
|
|
return Promise.reject(err.response.data)
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
)
|
141 |
|
|
|
142 |
|
|
export const fetchPlans = createAsyncThunk(
|
143 |
|
|
"searchForm/fetchPlans",
|
144 |
|
|
async () => {
|
145 |
|
|
try {
|
146 |
|
|
const response = await fetchPlanRequest()
|
147 |
|
|
if (response.status === 200) {
|
148 |
|
|
return response.data
|
149 |
|
|
} else {
|
150 |
|
|
return Promise.reject(response.data ? response.data : "Fetch plans failed")
|
151 |
|
|
}
|
152 |
|
|
} catch (err: any) {
|
153 |
|
|
return Promise.reject(err.response.data)
|
154 |
|
|
}
|
155 |
|
|
}
|
156 |
|
|
)
|