mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 22:06:29 +02:00
Add global variables for meeting dates
This commit is contained in:
72
src/store/miscDiscordInvitation.ts
Normal file
72
src/store/miscDiscordInvitation.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import _ from "lodash"
|
||||
import { PayloadAction, createSlice, createEntityAdapter, createSelector } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementListFetch } from "./utils"
|
||||
import { MiscDiscordInvitation } from "../services/miscs"
|
||||
import { AppThunk, AppState, EntitiesRequest } from "."
|
||||
import { miscDiscordInvitation } from "../services/miscsAccessors"
|
||||
|
||||
const miscAdapter = createEntityAdapter<MiscDiscordInvitation>()
|
||||
|
||||
export const initialState = miscAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest)
|
||||
|
||||
const miscDiscordInvitationSlice = createSlice({
|
||||
name: "miscDiscordInvitation",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<MiscDiscordInvitation[]>) => {
|
||||
state.readyStatus = "success"
|
||||
miscAdapter.setAll(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default miscDiscordInvitationSlice.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = miscDiscordInvitationSlice.actions
|
||||
|
||||
export const fetchMiscDiscordInvitation = elementListFetch(
|
||||
miscDiscordInvitation,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement des données diverses: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchMiscDiscordInvitation = (state: AppState) =>
|
||||
state.miscDiscordInvitation.readyStatus !== "success"
|
||||
|
||||
export const fetchMiscDiscordInvitationIfNeed = (): AppThunk => (dispatch, getState) => {
|
||||
const { jwt } = getState().auth
|
||||
if (shouldFetchMiscDiscordInvitation(getState()))
|
||||
return dispatch(fetchMiscDiscordInvitation(jwt))
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export const refreshMiscDiscordInvitation =
|
||||
(jwt: string): AppThunk =>
|
||||
(dispatch) =>
|
||||
dispatch(fetchMiscDiscordInvitation(jwt))
|
||||
|
||||
export const selectMiscDiscordInvitationState = (
|
||||
state: AppState
|
||||
): EntitiesRequest<MiscDiscordInvitation> => state.miscDiscordInvitation
|
||||
|
||||
export const selectMiscDiscordInvitation = createSelector(
|
||||
selectMiscDiscordInvitationState,
|
||||
({ ids, entities, readyStatus }) => {
|
||||
if (readyStatus !== "success") return ""
|
||||
const id = _.first(ids)
|
||||
if (id === undefined) return ""
|
||||
return entities[id]?.discordInvitation || ""
|
||||
}
|
||||
)
|
64
src/store/miscMeetingDateList.ts
Normal file
64
src/store/miscMeetingDateList.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { PayloadAction, createSlice, createEntityAdapter, createSelector } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, toastError, elementListFetch } from "./utils"
|
||||
import { MiscMeetingDate } from "../services/miscs"
|
||||
import { AppThunk, AppState, EntitiesRequest } from "."
|
||||
import { miscMeetingDateListGet } from "../services/miscsAccessors"
|
||||
|
||||
const miscAdapter = createEntityAdapter<MiscMeetingDate>()
|
||||
|
||||
export const initialState = miscAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest)
|
||||
|
||||
const miscMeetingDateList = createSlice({
|
||||
name: "miscMeetingDateList",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (state) => {
|
||||
state.readyStatus = "request"
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<MiscMeetingDate[]>) => {
|
||||
state.readyStatus = "success"
|
||||
miscAdapter.setAll(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
state.error = payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default miscMeetingDateList.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = miscMeetingDateList.actions
|
||||
|
||||
export const fetchMiscMeetingDateList = elementListFetch(
|
||||
miscMeetingDateListGet,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure,
|
||||
(error: Error) => toastError(`Erreur lors du chargement des données diverses: ${error.message}`)
|
||||
)
|
||||
|
||||
const shouldFetchMiscMeetingDateList = (state: AppState) =>
|
||||
state.miscMeetingDateList.readyStatus !== "success"
|
||||
|
||||
export const fetchMiscMeetingDateListIfNeed = (): AppThunk => (dispatch, getState) => {
|
||||
if (shouldFetchMiscMeetingDateList(getState())) return dispatch(fetchMiscMeetingDateList())
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export const refreshMiscMeetingDateList = (): AppThunk => (dispatch) =>
|
||||
dispatch(fetchMiscMeetingDateList())
|
||||
|
||||
export const selectMiscMeetingDateListState = (state: AppState): EntitiesRequest<MiscMeetingDate> =>
|
||||
state.miscMeetingDateList
|
||||
|
||||
export const selectMiscMeetingDateList = createSelector(
|
||||
selectMiscMeetingDateListState,
|
||||
({ ids, entities, readyStatus }) => {
|
||||
if (readyStatus !== "success") return []
|
||||
return ids.map((id) => entities[id]) as MiscMeetingDate[]
|
||||
}
|
||||
)
|
@@ -1,9 +1,11 @@
|
||||
import { History } from "history"
|
||||
import { connectRouter } from "connected-react-router"
|
||||
|
||||
import announcementList from "./announcementList"
|
||||
import auth from "./auth"
|
||||
import gameList from "./gameList"
|
||||
import announcementList from "./announcementList"
|
||||
import miscDiscordInvitation from "./miscDiscordInvitation"
|
||||
import miscMeetingDateList from "./miscMeetingDateList"
|
||||
import postulantAdd from "./postulantAdd"
|
||||
import teamList from "./teamList"
|
||||
import ui from "./ui"
|
||||
@@ -24,9 +26,11 @@ import wishList from "./wishList"
|
||||
// Use inferred return type for making correctly Redux types
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export default (history: History) => ({
|
||||
announcementList,
|
||||
auth,
|
||||
gameList,
|
||||
announcementList,
|
||||
miscDiscordInvitation,
|
||||
miscMeetingDateList,
|
||||
postulantAdd,
|
||||
teamList,
|
||||
ui,
|
||||
|
Reference in New Issue
Block a user