mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 22:06:29 +02:00
Rename all french to english
This commit is contained in:
@@ -2,14 +2,14 @@ import axios from "axios"
|
||||
import _ from "lodash"
|
||||
|
||||
import mockStore from "../../utils/mockStore"
|
||||
import JeuJavList, {
|
||||
import JavGameList, {
|
||||
initialState,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
fetchJeuJavList,
|
||||
} from "../jeuJavList"
|
||||
import { JeuJav } from "../../services/jeuxJav"
|
||||
fetchJavGameList,
|
||||
} from "../javGameList"
|
||||
import { JavGame } from "../../services/javGames"
|
||||
|
||||
jest.mock("axios")
|
||||
|
||||
@@ -33,7 +33,7 @@ const mockFrenchData: any[] = [
|
||||
ean: "3421272101313",
|
||||
},
|
||||
]
|
||||
const mockEnglishData: JeuJav[] = [
|
||||
const mockEnglishData: JavGame[] = [
|
||||
{
|
||||
id: 5,
|
||||
title: "6 qui prend!",
|
||||
@@ -55,14 +55,14 @@ const mockEnglishData: JeuJav[] = [
|
||||
]
|
||||
const mockError = "Oops! Something went wrong."
|
||||
|
||||
describe("JeuJavList reducer", () => {
|
||||
describe("JavGameList reducer", () => {
|
||||
it("should handle initial state", () => {
|
||||
// @ts-expect-error
|
||||
expect(JeuJavList(undefined, {})).toEqual(initialState)
|
||||
expect(JavGameList(undefined, {})).toEqual(initialState)
|
||||
})
|
||||
|
||||
it("should handle requesting correctly", () => {
|
||||
expect(JeuJavList(undefined, { type: getRequesting.type })).toEqual({
|
||||
expect(JavGameList(undefined, { type: getRequesting.type })).toEqual({
|
||||
readyStatus: "request",
|
||||
ids: [],
|
||||
entities: {},
|
||||
@@ -70,16 +70,18 @@ describe("JeuJavList reducer", () => {
|
||||
})
|
||||
|
||||
it("should handle success correctly", () => {
|
||||
expect(JeuJavList(undefined, { type: getSuccess.type, payload: mockEnglishData })).toEqual({
|
||||
...initialState,
|
||||
readyStatus: "success",
|
||||
ids: _.map(mockEnglishData, "id"),
|
||||
entities: _.keyBy(mockEnglishData, "id"),
|
||||
})
|
||||
expect(JavGameList(undefined, { type: getSuccess.type, payload: mockEnglishData })).toEqual(
|
||||
{
|
||||
...initialState,
|
||||
readyStatus: "success",
|
||||
ids: _.map(mockEnglishData, "id"),
|
||||
entities: _.keyBy(mockEnglishData, "id"),
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should handle failure correctly", () => {
|
||||
expect(JeuJavList(undefined, { type: getFailure.type, payload: mockError })).toEqual({
|
||||
expect(JavGameList(undefined, { type: getFailure.type, payload: mockError })).toEqual({
|
||||
...initialState,
|
||||
readyStatus: "failure",
|
||||
error: mockError,
|
||||
@@ -87,8 +89,8 @@ describe("JeuJavList reducer", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("JeuJavList action", () => {
|
||||
it("fetches JeuJav list successful", async () => {
|
||||
describe("JavGameList action", () => {
|
||||
it("fetches JavGame list successful", async () => {
|
||||
const { dispatch, getActions } = mockStore()
|
||||
const expectedActions = [
|
||||
{ type: getRequesting.type, payload: undefined },
|
||||
@@ -98,11 +100,11 @@ describe("JeuJavList action", () => {
|
||||
// @ts-expect-error
|
||||
axios.get.mockResolvedValue({ data: mockFrenchData })
|
||||
|
||||
await dispatch(fetchJeuJavList())
|
||||
await dispatch(fetchJavGameList())
|
||||
expect(getActions()).toEqual(expectedActions)
|
||||
})
|
||||
|
||||
it("fetches JeuJav list failed", async () => {
|
||||
it("fetches JavGame list failed", async () => {
|
||||
const { dispatch, getActions } = mockStore()
|
||||
const expectedActions = [
|
||||
{ type: getRequesting.type },
|
||||
@@ -112,7 +114,7 @@ describe("JeuJavList action", () => {
|
||||
// @ts-expect-error
|
||||
axios.get.mockRejectedValue({ message: mockError })
|
||||
|
||||
await dispatch(fetchJeuJavList())
|
||||
await dispatch(fetchJavGameList())
|
||||
expect(getActions()).toEqual(expectedActions)
|
||||
})
|
||||
})
|
@@ -1,8 +1,14 @@
|
||||
import axios from "axios"
|
||||
|
||||
import mockStore from "../../utils/mockStore"
|
||||
import membre, { getRequesting, getSuccess, getFailure, fetchMembre, initialState } from "../membre"
|
||||
import { Membre } from "../../services/membres"
|
||||
import volunteer, {
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
fetchVolunteer,
|
||||
initialState,
|
||||
} from "../volunteer"
|
||||
import { Volunteer } from "../../services/volunteers"
|
||||
|
||||
jest.mock("axios")
|
||||
|
||||
@@ -12,7 +18,7 @@ const mockFrenchData: any = {
|
||||
prenom: "Amélie",
|
||||
mail: "pakouille.lakouille@yahoo.fr",
|
||||
telephone: "0675650392",
|
||||
photo: "images/membres/$taille/amélie_aupeix.jpg",
|
||||
photo: "images/volunteers/$taille/amélie_aupeix.jpg",
|
||||
alimentation: "Végétarien",
|
||||
majeur: 1,
|
||||
privilege: 0,
|
||||
@@ -22,13 +28,13 @@ const mockFrenchData: any = {
|
||||
passe: "$2y$10$fSxY9AIuxSiEjwF.J3eXGubIxUPlobkyRrNIal8ASimSjNj4SR.9O",
|
||||
}
|
||||
|
||||
const mockEnglishData: Membre = {
|
||||
const mockEnglishData: Volunteer = {
|
||||
id: 1,
|
||||
lastname: "Aupeix",
|
||||
firstname: "Amélie",
|
||||
email: "pakouille.lakouille@yahoo.fr",
|
||||
mobile: "0675650392",
|
||||
photo: "images/membres/$taille/amélie_aupeix.jpg",
|
||||
photo: "images/volunteers/$taille/amélie_aupeix.jpg",
|
||||
food: "Végétarien",
|
||||
adult: 1,
|
||||
privileges: 0,
|
||||
@@ -40,21 +46,21 @@ const mockEnglishData: Membre = {
|
||||
const { id } = mockEnglishData
|
||||
const mockError = "Oops! Something went wrong."
|
||||
|
||||
describe("membre reducer", () => {
|
||||
describe("volunteer reducer", () => {
|
||||
it("should handle initial state correctly", () => {
|
||||
// @ts-expect-error
|
||||
expect(membre(undefined, {})).toEqual(initialState)
|
||||
expect(volunteer(undefined, {})).toEqual(initialState)
|
||||
})
|
||||
|
||||
it("should handle requesting correctly", () => {
|
||||
expect(membre(undefined, { type: getRequesting.type, payload: id })).toEqual({
|
||||
expect(volunteer(undefined, { type: getRequesting.type, payload: id })).toEqual({
|
||||
readyStatus: "request",
|
||||
})
|
||||
})
|
||||
|
||||
it("should handle success correctly", () => {
|
||||
expect(
|
||||
membre(undefined, {
|
||||
volunteer(undefined, {
|
||||
type: getSuccess.type,
|
||||
payload: mockEnglishData,
|
||||
})
|
||||
@@ -63,7 +69,7 @@ describe("membre reducer", () => {
|
||||
|
||||
it("should handle failure correctly", () => {
|
||||
expect(
|
||||
membre(undefined, {
|
||||
volunteer(undefined, {
|
||||
type: getFailure.type,
|
||||
payload: mockError,
|
||||
})
|
||||
@@ -71,8 +77,8 @@ describe("membre reducer", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("membre action", () => {
|
||||
it("fetches membre data successful", async () => {
|
||||
describe("volunteer action", () => {
|
||||
it("fetches volunteer data successful", async () => {
|
||||
const { dispatch, getActions } = mockStore()
|
||||
const expectedActions = [
|
||||
{ type: getRequesting.type, payload: undefined },
|
||||
@@ -82,11 +88,11 @@ describe("membre action", () => {
|
||||
// @ts-expect-error
|
||||
axios.get.mockResolvedValue({ data: mockFrenchData })
|
||||
|
||||
await dispatch(fetchMembre(id))
|
||||
await dispatch(fetchVolunteer(id))
|
||||
expect(getActions()).toEqual(expectedActions)
|
||||
})
|
||||
|
||||
it("fetches membre data failed", async () => {
|
||||
it("fetches volunteer data failed", async () => {
|
||||
const { dispatch, getActions } = mockStore()
|
||||
const expectedActions = [
|
||||
{ type: getRequesting.type },
|
||||
@@ -96,7 +102,7 @@ describe("membre action", () => {
|
||||
// @ts-expect-error
|
||||
axios.get.mockRejectedValue({ message: mockError })
|
||||
|
||||
await dispatch(fetchMembre(id))
|
||||
await dispatch(fetchVolunteer(id))
|
||||
expect(getActions()).toEqual(expectedActions)
|
||||
})
|
||||
})
|
@@ -2,14 +2,14 @@ import axios from "axios"
|
||||
import _ from "lodash"
|
||||
|
||||
import mockStore from "../../utils/mockStore"
|
||||
import membreList, {
|
||||
import volunteerList, {
|
||||
initialState,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
fetchMembreList,
|
||||
} from "../membreList"
|
||||
import { Membre } from "../../services/membres"
|
||||
fetchVolunteerList,
|
||||
} from "../volunteerList"
|
||||
import { Volunteer } from "../../services/volunteers"
|
||||
|
||||
jest.mock("axios")
|
||||
|
||||
@@ -20,7 +20,7 @@ const mockFrenchData: any[] = [
|
||||
prenom: "Amélie",
|
||||
mail: "pakouille.lakouille@yahoo.fr",
|
||||
telephone: "0675650392",
|
||||
photo: "images/membres/$taille/amélie_aupeix.jpg",
|
||||
photo: "images/volunteers/$taille/amélie_aupeix.jpg",
|
||||
alimentation: "Végétarien",
|
||||
majeur: 1,
|
||||
privilege: 0,
|
||||
@@ -31,14 +31,14 @@ const mockFrenchData: any[] = [
|
||||
},
|
||||
]
|
||||
|
||||
const mockEnglishData: Membre[] = [
|
||||
const mockEnglishData: Volunteer[] = [
|
||||
{
|
||||
id: 1,
|
||||
lastname: "Aupeix",
|
||||
firstname: "Amélie",
|
||||
email: "pakouille.lakouille@yahoo.fr",
|
||||
mobile: "0675650392",
|
||||
photo: "images/membres/$taille/amélie_aupeix.jpg",
|
||||
photo: "images/volunteers/$taille/amélie_aupeix.jpg",
|
||||
food: "Végétarien",
|
||||
adult: 1,
|
||||
privileges: 0,
|
||||
@@ -50,14 +50,14 @@ const mockEnglishData: Membre[] = [
|
||||
]
|
||||
const mockError = "Oops! Something went wrong."
|
||||
|
||||
describe("membreList reducer", () => {
|
||||
describe("volunteerList reducer", () => {
|
||||
it("should handle initial state", () => {
|
||||
// @ts-expect-error
|
||||
expect(membreList(undefined, {})).toEqual(initialState)
|
||||
expect(volunteerList(undefined, {})).toEqual(initialState)
|
||||
})
|
||||
|
||||
it("should handle requesting correctly", () => {
|
||||
expect(membreList(undefined, { type: getRequesting.type })).toEqual({
|
||||
expect(volunteerList(undefined, { type: getRequesting.type })).toEqual({
|
||||
readyStatus: "request",
|
||||
ids: [],
|
||||
entities: {},
|
||||
@@ -65,7 +65,9 @@ describe("membreList reducer", () => {
|
||||
})
|
||||
|
||||
it("should handle success correctly", () => {
|
||||
expect(membreList(undefined, { type: getSuccess.type, payload: mockEnglishData })).toEqual({
|
||||
expect(
|
||||
volunteerList(undefined, { type: getSuccess.type, payload: mockEnglishData })
|
||||
).toEqual({
|
||||
...initialState,
|
||||
readyStatus: "success",
|
||||
ids: _.map(mockEnglishData, "id"),
|
||||
@@ -74,7 +76,7 @@ describe("membreList reducer", () => {
|
||||
})
|
||||
|
||||
it("should handle failure correctly", () => {
|
||||
expect(membreList(undefined, { type: getFailure.type, payload: mockError })).toEqual({
|
||||
expect(volunteerList(undefined, { type: getFailure.type, payload: mockError })).toEqual({
|
||||
...initialState,
|
||||
readyStatus: "failure",
|
||||
error: mockError,
|
||||
@@ -82,8 +84,8 @@ describe("membreList reducer", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("membreList action", () => {
|
||||
it("fetches membre list successful", async () => {
|
||||
describe("volunteerList action", () => {
|
||||
it("fetches volunteer list successful", async () => {
|
||||
const { dispatch, getActions } = mockStore()
|
||||
const expectedActions = [
|
||||
{ type: getRequesting.type, payload: undefined },
|
||||
@@ -93,11 +95,11 @@ describe("membreList action", () => {
|
||||
// @ts-expect-error
|
||||
axios.get.mockResolvedValue({ data: mockFrenchData })
|
||||
|
||||
await dispatch(fetchMembreList())
|
||||
await dispatch(fetchVolunteerList())
|
||||
expect(getActions()).toEqual(expectedActions)
|
||||
})
|
||||
|
||||
it("fetches membre list failed", async () => {
|
||||
it("fetches volunteer list failed", async () => {
|
||||
const { dispatch, getActions } = mockStore()
|
||||
const expectedActions = [
|
||||
{ type: getRequesting.type },
|
||||
@@ -107,7 +109,7 @@ describe("membreList action", () => {
|
||||
// @ts-expect-error
|
||||
axios.get.mockRejectedValue({ message: mockError })
|
||||
|
||||
await dispatch(fetchMembreList())
|
||||
await dispatch(fetchVolunteerList())
|
||||
expect(getActions()).toEqual(expectedActions)
|
||||
})
|
||||
})
|
@@ -1,38 +0,0 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, toastSuccess, elementAddFetch } from "./utils"
|
||||
import { Envie, envieAdd } from "../services/envies"
|
||||
|
||||
const envieAdapter = createEntityAdapter<Envie>()
|
||||
|
||||
const envieAddSlice = createSlice({
|
||||
name: "addEnvie",
|
||||
initialState: envieAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Envie>) => {
|
||||
state.readyStatus = "success"
|
||||
envieAdapter.addOne(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default envieAddSlice.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = envieAddSlice.actions
|
||||
|
||||
export const fetchEnvieAdd = elementAddFetch(
|
||||
envieAdd,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors de l'ajout d'une envie: ${error.message}`),
|
||||
() => toastSuccess("Envie ajoutée !")
|
||||
)
|
@@ -1,46 +0,0 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementListFetch } from "./utils"
|
||||
import { Envie, envieListGet } from "../services/envies"
|
||||
import { AppThunk, AppState } from "."
|
||||
|
||||
const envieAdapter = createEntityAdapter<Envie>()
|
||||
|
||||
const envieList = createSlice({
|
||||
name: "getEnvieList",
|
||||
initialState: envieAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Envie[]>) => {
|
||||
state.readyStatus = "success"
|
||||
envieAdapter.setAll(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default envieList.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = envieList.actions
|
||||
|
||||
export const fetchEnvieList = elementListFetch(
|
||||
envieListGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement des envies: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchEnvieList = (state: AppState) => state.envieList.readyStatus !== "success"
|
||||
|
||||
export const fetchEnvieListIfNeed = (): AppThunk => (dispatch, getState) => {
|
||||
if (shouldFetchEnvieList(getState())) return dispatch(fetchEnvieList())
|
||||
|
||||
return null
|
||||
}
|
48
src/store/javGameList.ts
Normal file
48
src/store/javGameList.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementListFetch } from "./utils"
|
||||
import { JavGame, javGameListGet } from "../services/javGames"
|
||||
import { AppThunk, AppState } from "."
|
||||
|
||||
const javGameAdapter = createEntityAdapter<JavGame>()
|
||||
|
||||
export const initialState = javGameAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest)
|
||||
|
||||
const javGameList = createSlice({
|
||||
name: "javGameList",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<JavGame[]>) => {
|
||||
state.readyStatus = "success"
|
||||
javGameAdapter.setAll(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default javGameList.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = javGameList.actions
|
||||
|
||||
export const fetchJavGameList = elementListFetch(
|
||||
javGameListGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement des jeux JAV: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchJavGameList = (state: AppState) => state.javGameList.readyStatus !== "success"
|
||||
|
||||
export const fetchJavGameListIfNeed = (): AppThunk => (dispatch, getState) => {
|
||||
if (shouldFetchJavGameList(getState())) return dispatch(fetchJavGameList())
|
||||
|
||||
return null
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementListFetch } from "./utils"
|
||||
import { JeuJav, jeuJavListGet } from "../services/jeuxJav"
|
||||
import { AppThunk, AppState } from "."
|
||||
|
||||
const jeuJavAdapter = createEntityAdapter<JeuJav>()
|
||||
|
||||
export const initialState = jeuJavAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest)
|
||||
|
||||
const jeuJavList = createSlice({
|
||||
name: "jeuJavList",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<JeuJav[]>) => {
|
||||
state.readyStatus = "success"
|
||||
jeuJavAdapter.setAll(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default jeuJavList.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = jeuJavList.actions
|
||||
|
||||
export const fetchJeuJavList = elementListFetch(
|
||||
jeuJavListGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement des jeux JAV: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchJeuJavList = (state: AppState) => state.jeuJavList.readyStatus !== "success"
|
||||
|
||||
export const fetchJeuJavListIfNeed = (): AppThunk => (dispatch, getState) => {
|
||||
if (shouldFetchJeuJavList(getState())) return dispatch(fetchJeuJavList())
|
||||
|
||||
return null
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
import { PayloadAction, createSlice } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementFetch } from "./utils"
|
||||
import { Membre, membreGet } from "../services/membres"
|
||||
import { AppThunk, AppState } from "."
|
||||
|
||||
type StateMembre = { entity?: Membre } & StateRequest
|
||||
|
||||
export const initialState: StateMembre = {
|
||||
readyStatus: "idle",
|
||||
}
|
||||
|
||||
const membre = createSlice({
|
||||
name: "membre",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (_) => ({
|
||||
readyStatus: "request",
|
||||
}),
|
||||
getSuccess: (_, { payload }: PayloadAction<Membre>) => ({
|
||||
readyStatus: "success",
|
||||
entity: payload,
|
||||
}),
|
||||
getFailure: (_, { payload }: PayloadAction<string>) => ({
|
||||
readyStatus: "failure",
|
||||
error: payload,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
export default membre.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = membre.actions
|
||||
|
||||
export const fetchMembre = elementFetch(
|
||||
membreGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement d'un membre: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchMembre = (state: AppState, id: number) =>
|
||||
state.membre.readyStatus !== "success" || (state.membre.entity && state.membre.entity.id !== id)
|
||||
|
||||
export const fetchMembreIfNeed =
|
||||
(id: number): AppThunk =>
|
||||
(dispatch, getState) => {
|
||||
if (shouldFetchMembre(getState(), id)) return dispatch(fetchMembre(id))
|
||||
|
||||
return null
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, toastSuccess, elementAddFetch } from "./utils"
|
||||
import { Membre, membreAdd } from "../services/membres"
|
||||
|
||||
const membreAdapter = createEntityAdapter<Membre>()
|
||||
|
||||
const membreAddSlice = createSlice({
|
||||
name: "addMembre",
|
||||
initialState: membreAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Membre>) => {
|
||||
state.readyStatus = "success"
|
||||
membreAdapter.addOne(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default membreAddSlice.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = membreAddSlice.actions
|
||||
|
||||
export const fetchMembreAdd = elementAddFetch(
|
||||
membreAdd,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors de l'ajout d'une membre: ${error.message}`),
|
||||
() => toastSuccess("Membre ajoutée !")
|
||||
)
|
@@ -1,48 +0,0 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementListFetch } from "./utils"
|
||||
import { Membre, membreListGet } from "../services/membres"
|
||||
import { AppThunk, AppState } from "."
|
||||
|
||||
const membreAdapter = createEntityAdapter<Membre>()
|
||||
|
||||
export const initialState = membreAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest)
|
||||
|
||||
const membreList = createSlice({
|
||||
name: "membreList",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Membre[]>) => {
|
||||
state.readyStatus = "success"
|
||||
membreAdapter.setAll(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default membreList.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = membreList.actions
|
||||
|
||||
export const fetchMembreList = elementListFetch(
|
||||
membreListGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement des membres: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchMembreList = (state: AppState) => state.membreList.readyStatus !== "success"
|
||||
|
||||
export const fetchMembreListIfNeed = (): AppThunk => (dispatch, getState) => {
|
||||
if (shouldFetchMembreList(getState())) return dispatch(fetchMembreList())
|
||||
|
||||
return null
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, elementAddFetch } from "./utils"
|
||||
import { PreMember, preMemberAdd } from "../services/preMembers"
|
||||
import { PreMember, preMemberAdd } from "../services/preVolunteers"
|
||||
|
||||
const preMemberAdapter = createEntityAdapter<PreMember>()
|
||||
|
@@ -1,25 +1,25 @@
|
||||
import { History } from "history"
|
||||
import { connectRouter } from "connected-react-router"
|
||||
|
||||
import envieAdd from "./envieAdd"
|
||||
import envieList from "./envieList"
|
||||
import jeuJavList from "./jeuJavList"
|
||||
import membre from "./membre"
|
||||
import membreAdd from "./membreAdd"
|
||||
import membreList from "./membreList"
|
||||
import membreSet from "./membreSet"
|
||||
import preMemberAdd from "./preMemberAdd"
|
||||
import wishAdd from "./wishAdd"
|
||||
import wishList from "./wishList"
|
||||
import javGameList from "./javGameList"
|
||||
import volunteer from "./volunteer"
|
||||
import volunteerAdd from "./volunteerAdd"
|
||||
import volunteerList from "./volunteerList"
|
||||
import volunteerSet from "./volunteerSet"
|
||||
import preMemberAdd from "./preVolunteerAdd"
|
||||
|
||||
// Use inferred return type for making correctly Redux types
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export default (history: History) => ({
|
||||
envieAdd,
|
||||
envieList,
|
||||
jeuJavList,
|
||||
membre,
|
||||
membreAdd,
|
||||
membreList,
|
||||
membreSet,
|
||||
wishAdd,
|
||||
wishList,
|
||||
javGameList,
|
||||
volunteer,
|
||||
volunteerAdd,
|
||||
volunteerList,
|
||||
volunteerSet,
|
||||
preMemberAdd,
|
||||
router: connectRouter(history) as any,
|
||||
// Register more reducers...
|
||||
|
@@ -64,7 +64,7 @@ export function elementFetch<Element>(
|
||||
}
|
||||
|
||||
export function elementAddFetch<Element>(
|
||||
elementAddService: (membreWithoutId: Omit<Element, "id">) => Promise<{
|
||||
elementAddService: (volunteerWithoutId: Omit<Element, "id">) => Promise<{
|
||||
data?: Element | undefined
|
||||
error?: Error | undefined
|
||||
}>,
|
||||
@@ -77,12 +77,12 @@ export function elementAddFetch<Element>(
|
||||
successMessage: () => void = () => {
|
||||
/* Meant to be empty */
|
||||
}
|
||||
): (membreWithoutId: Omit<Element, "id">) => AppThunk {
|
||||
return (membreWithoutId: Omit<Element, "id">): AppThunk =>
|
||||
): (volunteerWithoutId: Omit<Element, "id">) => AppThunk {
|
||||
return (volunteerWithoutId: Omit<Element, "id">): AppThunk =>
|
||||
async (dispatch) => {
|
||||
dispatch(getRequesting())
|
||||
|
||||
const { error, data } = await elementAddService(membreWithoutId)
|
||||
const { error, data } = await elementAddService(volunteerWithoutId)
|
||||
|
||||
if (error) {
|
||||
dispatch(getFailure(error.message))
|
||||
@@ -125,7 +125,7 @@ export function elementListFetch<Element>(
|
||||
}
|
||||
|
||||
export function elementSet<Element>(
|
||||
elementSetService: (membre: Element) => Promise<{
|
||||
elementSetService: (volunteer: Element) => Promise<{
|
||||
data?: Element | undefined
|
||||
error?: Error | undefined
|
||||
}>,
|
||||
|
52
src/store/volunteer.ts
Normal file
52
src/store/volunteer.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { PayloadAction, createSlice } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementFetch } from "./utils"
|
||||
import { Volunteer, volunteerGet } from "../services/volunteers"
|
||||
import { AppThunk, AppState } from "."
|
||||
|
||||
type StateVolunteer = { entity?: Volunteer } & StateRequest
|
||||
|
||||
export const initialState: StateVolunteer = {
|
||||
readyStatus: "idle",
|
||||
}
|
||||
|
||||
const volunteer = createSlice({
|
||||
name: "volunteer",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (_) => ({
|
||||
readyStatus: "request",
|
||||
}),
|
||||
getSuccess: (_, { payload }: PayloadAction<Volunteer>) => ({
|
||||
readyStatus: "success",
|
||||
entity: payload,
|
||||
}),
|
||||
getFailure: (_, { payload }: PayloadAction<string>) => ({
|
||||
readyStatus: "failure",
|
||||
error: payload,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
export default volunteer.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = volunteer.actions
|
||||
|
||||
export const fetchVolunteer = elementFetch(
|
||||
volunteerGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement d'un volunteer: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchVolunteer = (state: AppState, id: number) =>
|
||||
state.volunteer.readyStatus !== "success" ||
|
||||
(state.volunteer.entity && state.volunteer.entity.id !== id)
|
||||
|
||||
export const fetchVolunteerIfNeed =
|
||||
(id: number): AppThunk =>
|
||||
(dispatch, getState) => {
|
||||
if (shouldFetchVolunteer(getState(), id)) return dispatch(fetchVolunteer(id))
|
||||
|
||||
return null
|
||||
}
|
38
src/store/volunteerAdd.ts
Normal file
38
src/store/volunteerAdd.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, toastSuccess, elementAddFetch } from "./utils"
|
||||
import { Volunteer, volunteerAdd } from "../services/volunteers"
|
||||
|
||||
const volunteerAdapter = createEntityAdapter<Volunteer>()
|
||||
|
||||
const volunteerAddSlice = createSlice({
|
||||
name: "addVolunteer",
|
||||
initialState: volunteerAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Volunteer>) => {
|
||||
state.readyStatus = "success"
|
||||
volunteerAdapter.addOne(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default volunteerAddSlice.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = volunteerAddSlice.actions
|
||||
|
||||
export const fetchVolunteerAdd = elementAddFetch(
|
||||
volunteerAdd,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors de l'ajout d'une volunteer: ${error.message}`),
|
||||
() => toastSuccess("Volunteer ajoutée !")
|
||||
)
|
48
src/store/volunteerList.ts
Normal file
48
src/store/volunteerList.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementListFetch } from "./utils"
|
||||
import { Volunteer, volunteerListGet } from "../services/volunteers"
|
||||
import { AppThunk, AppState } from "."
|
||||
|
||||
const volunteerAdapter = createEntityAdapter<Volunteer>()
|
||||
|
||||
export const initialState = volunteerAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest)
|
||||
|
||||
const volunteerList = createSlice({
|
||||
name: "volunteerList",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Volunteer[]>) => {
|
||||
state.readyStatus = "success"
|
||||
volunteerAdapter.setAll(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default volunteerList.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = volunteerList.actions
|
||||
|
||||
export const fetchVolunteerList = elementListFetch(
|
||||
volunteerListGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement des volunteers: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchVolunteerList = (state: AppState) => state.volunteerList.readyStatus !== "success"
|
||||
|
||||
export const fetchVolunteerListIfNeed = (): AppThunk => (dispatch, getState) => {
|
||||
if (shouldFetchVolunteerList(getState())) return dispatch(fetchVolunteerList())
|
||||
|
||||
return null
|
||||
}
|
@@ -1,22 +1,22 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, toastSuccess, elementSet } from "./utils"
|
||||
import { Membre, membreSet } from "../services/membres"
|
||||
import { Volunteer, volunteerSet } from "../services/volunteers"
|
||||
|
||||
const membreAdapter = createEntityAdapter<Membre>()
|
||||
const volunteerAdapter = createEntityAdapter<Volunteer>()
|
||||
|
||||
const membreSetSlice = createSlice({
|
||||
name: "membreSet",
|
||||
initialState: membreAdapter.getInitialState({
|
||||
const volunteerSetSlice = createSlice({
|
||||
name: "volunteerSet",
|
||||
initialState: volunteerAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Membre>) => {
|
||||
getSuccess: (state, { payload }: PayloadAction<Volunteer>) => {
|
||||
state.readyStatus = "success"
|
||||
membreAdapter.setOne(state, payload)
|
||||
volunteerAdapter.setOne(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
@@ -25,14 +25,14 @@ const membreSetSlice = createSlice({
|
||||
},
|
||||
})
|
||||
|
||||
export default membreSetSlice.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = membreSetSlice.actions
|
||||
export default volunteerSetSlice.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = volunteerSetSlice.actions
|
||||
|
||||
export const fetchMembreSet = elementSet(
|
||||
membreSet,
|
||||
export const fetchVolunteerSet = elementSet(
|
||||
volunteerSet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors de la modification d'un membre: ${error.message}`),
|
||||
() => toastSuccess("Membre modifié !")
|
||||
(error: Error) => toastError(`Erreur lors de la modification d'un volunteer: ${error.message}`),
|
||||
() => toastSuccess("Volunteer modifié !")
|
||||
)
|
38
src/store/wishAdd.ts
Normal file
38
src/store/wishAdd.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, toastSuccess, elementAddFetch } from "./utils"
|
||||
import { Wish, wishAdd } from "../services/wishes"
|
||||
|
||||
const wishAdapter = createEntityAdapter<Wish>()
|
||||
|
||||
const wishAddSlice = createSlice({
|
||||
name: "addWish",
|
||||
initialState: wishAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Wish>) => {
|
||||
state.readyStatus = "success"
|
||||
wishAdapter.addOne(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default wishAddSlice.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = wishAddSlice.actions
|
||||
|
||||
export const fetchWishAdd = elementAddFetch(
|
||||
wishAdd,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors de l'ajout d'une wish: ${error.message}`),
|
||||
() => toastSuccess("Wish ajoutée !")
|
||||
)
|
46
src/store/wishList.ts
Normal file
46
src/store/wishList.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementListFetch } from "./utils"
|
||||
import { Wish, wishListGet } from "../services/wishes"
|
||||
import { AppThunk, AppState } from "."
|
||||
|
||||
const wishAdapter = createEntityAdapter<Wish>()
|
||||
|
||||
const wishList = createSlice({
|
||||
name: "getWishList",
|
||||
initialState: wishAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Wish[]>) => {
|
||||
state.readyStatus = "success"
|
||||
wishAdapter.setAll(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default wishList.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = wishList.actions
|
||||
|
||||
export const fetchWishList = elementListFetch(
|
||||
wishListGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement des wishes: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchWishList = (state: AppState) => state.wishList.readyStatus !== "success"
|
||||
|
||||
export const fetchWishListIfNeed = (): AppThunk => (dispatch, getState) => {
|
||||
if (shouldFetchWishList(getState())) return dispatch(fetchWishList())
|
||||
|
||||
return null
|
||||
}
|
Reference in New Issue
Block a user