mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 22:06:29 +02:00
Add password reset
This commit is contained in:
@@ -23,9 +23,9 @@ const mockData: Volunteer = {
|
||||
adult: 1,
|
||||
privileges: 0,
|
||||
active: 0,
|
||||
comment: "",
|
||||
timestamp: new Date(0),
|
||||
password: "$2y$10$fSxY9AIuxSiEjwF.J3eXGubIxUPlobkyRrNIal8ASimSjNj4SR.9O",
|
||||
created: new Date(0),
|
||||
password1: "$2y$10$fSxY9AIuxSiEjwF.J3eXGubIxUPlobkyRrNIal8ASimSjNj4SR.9O",
|
||||
password2: "$2y$10$fSxY9AIuxSiEjwF.J3eXGubIxUPlobkyRrNIal8ASimSjNj4SR.9O",
|
||||
}
|
||||
const { id } = mockData
|
||||
const mockError = "Oops! Something went wrong."
|
||||
|
@@ -25,9 +25,9 @@ const mockData: Volunteer[] = [
|
||||
adult: 1,
|
||||
privileges: 0,
|
||||
active: 0,
|
||||
comment: "",
|
||||
timestamp: new Date(0),
|
||||
password: "$2y$10$fSxY9AIuxSiEjwF.J3eXGubIxUPlobkyRrNIal8ASimSjNj4SR.9O",
|
||||
created: new Date(0),
|
||||
password1: "$2y$10$fSxY9AIuxSiEjwF.J3eXGubIxUPlobkyRrNIal8ASimSjNj4SR.9O",
|
||||
password2: "$2y$10$fSxY9AIuxSiEjwF.J3eXGubIxUPlobkyRrNIal8ASimSjNj4SR.9O",
|
||||
},
|
||||
]
|
||||
const mockError = "Oops! Something went wrong."
|
||||
|
@@ -9,6 +9,7 @@ import volunteerAdd from "./volunteerAdd"
|
||||
import volunteerList from "./volunteerList"
|
||||
import volunteerSet from "./volunteerSet"
|
||||
import volunteerLogin from "./volunteerLogin"
|
||||
import volunteerForgot from "./volunteerForgot"
|
||||
import preVolunteerAdd from "./preVolunteerAdd"
|
||||
import preVolunteerCount from "./preVolunteerCount"
|
||||
|
||||
@@ -23,6 +24,7 @@ export default (history: History) => ({
|
||||
volunteerList,
|
||||
volunteerSet,
|
||||
volunteerLogin,
|
||||
volunteerForgot,
|
||||
preVolunteerAdd,
|
||||
preVolunteerCount,
|
||||
router: connectRouter(history) as any,
|
||||
|
@@ -51,14 +51,10 @@ export function elementFetch<Element>(
|
||||
|
||||
if (error) {
|
||||
dispatch(getFailure(error.message))
|
||||
if (errorMessage) {
|
||||
errorMessage(error)
|
||||
}
|
||||
errorMessage?.(error)
|
||||
} else {
|
||||
dispatch(getSuccess(data as Element))
|
||||
if (successMessage) {
|
||||
successMessage(data as Element)
|
||||
}
|
||||
successMessage?.(data as Element)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,12 +67,8 @@ export function elementAddFetch<Element>(
|
||||
getRequesting: ActionCreatorWithoutPayload<string>,
|
||||
getSuccess: ActionCreatorWithPayload<Element, string>,
|
||||
getFailure: ActionCreatorWithPayload<string, string>,
|
||||
errorMessage: (error: Error) => void = (_error) => {
|
||||
/* Meant to be empty */
|
||||
},
|
||||
successMessage: () => void = () => {
|
||||
/* Meant to be empty */
|
||||
}
|
||||
errorMessage?: (error: Error) => void,
|
||||
successMessage?: () => void
|
||||
): (volunteerWithoutId: Omit<Element, "id">) => AppThunk {
|
||||
return (volunteerWithoutId: Omit<Element, "id">): AppThunk =>
|
||||
async (dispatch) => {
|
||||
@@ -86,10 +78,10 @@ export function elementAddFetch<Element>(
|
||||
|
||||
if (error) {
|
||||
dispatch(getFailure(error.message))
|
||||
errorMessage(error)
|
||||
errorMessage?.(error)
|
||||
} else {
|
||||
dispatch(getSuccess(data as Element))
|
||||
successMessage()
|
||||
successMessage?.()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,12 +94,8 @@ export function elementListFetch<Element>(
|
||||
getRequesting: ActionCreatorWithoutPayload<string>,
|
||||
getSuccess: ActionCreatorWithPayload<Element[], string>,
|
||||
getFailure: ActionCreatorWithPayload<string, string>,
|
||||
errorMessage: (error: Error) => void = (_error) => {
|
||||
/* Meant to be empty */
|
||||
},
|
||||
successMessage: () => void = () => {
|
||||
/* Meant to be empty */
|
||||
}
|
||||
errorMessage?: (error: Error) => void,
|
||||
successMessage?: () => void
|
||||
): () => AppThunk {
|
||||
return (): AppThunk => async (dispatch) => {
|
||||
dispatch(getRequesting())
|
||||
@@ -116,10 +104,10 @@ export function elementListFetch<Element>(
|
||||
|
||||
if (error) {
|
||||
dispatch(getFailure(error.message))
|
||||
errorMessage(error)
|
||||
errorMessage?.(error)
|
||||
} else {
|
||||
dispatch(getSuccess(data as Element[]))
|
||||
successMessage()
|
||||
successMessage?.()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,12 +120,8 @@ export function elementSet<Element>(
|
||||
getRequesting: ActionCreatorWithoutPayload<string>,
|
||||
getSuccess: ActionCreatorWithPayload<Element, string>,
|
||||
getFailure: ActionCreatorWithPayload<string, string>,
|
||||
errorMessage: (error: Error) => void = (_error) => {
|
||||
/* Meant to be empty */
|
||||
},
|
||||
successMessage: () => void = () => {
|
||||
/* Meant to be empty */
|
||||
}
|
||||
errorMessage?: (error: Error) => void,
|
||||
successMessage?: () => void
|
||||
): (element: Element) => AppThunk {
|
||||
return (element: Element): AppThunk =>
|
||||
async (dispatch) => {
|
||||
@@ -147,10 +131,10 @@ export function elementSet<Element>(
|
||||
|
||||
if (error) {
|
||||
dispatch(getFailure(error.message))
|
||||
errorMessage(error)
|
||||
errorMessage?.(error)
|
||||
} else {
|
||||
dispatch(getSuccess(data as Element))
|
||||
successMessage()
|
||||
successMessage?.()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,12 +147,8 @@ export function elementValueFetch<Element>(
|
||||
getRequesting: ActionCreatorWithoutPayload<string>,
|
||||
getSuccess: ActionCreatorWithPayload<Element, string>,
|
||||
getFailure: ActionCreatorWithPayload<string, string>,
|
||||
errorMessage: (error: Error) => void = (_error) => {
|
||||
/* Meant to be empty */
|
||||
},
|
||||
successMessage: () => void = () => {
|
||||
/* Meant to be empty */
|
||||
}
|
||||
errorMessage?: (error: Error) => void,
|
||||
successMessage?: () => void
|
||||
): () => AppThunk {
|
||||
return (): AppThunk => async (dispatch) => {
|
||||
dispatch(getRequesting())
|
||||
@@ -177,10 +157,10 @@ export function elementValueFetch<Element>(
|
||||
|
||||
if (error) {
|
||||
dispatch(getFailure(error.message))
|
||||
errorMessage(error)
|
||||
errorMessage?.(error)
|
||||
} else {
|
||||
dispatch(getSuccess(data as Element))
|
||||
successMessage()
|
||||
successMessage?.()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
src/store/volunteerForgot.ts
Normal file
38
src/store/volunteerForgot.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { PayloadAction, createSlice } from "@reduxjs/toolkit"
|
||||
|
||||
import { StateRequest, elementFetch } from "./utils"
|
||||
import { VolunteerForgot, volunteerForgot } from "../services/volunteers"
|
||||
|
||||
type StateVolunteer = { entity?: VolunteerForgot } & StateRequest
|
||||
|
||||
export const initialState: StateVolunteer = {
|
||||
readyStatus: "idle",
|
||||
}
|
||||
|
||||
const volunteerForgotSlice = createSlice({
|
||||
name: "volunteerForgot",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (_) => ({
|
||||
readyStatus: "request",
|
||||
}),
|
||||
getSuccess: (_, { payload }: PayloadAction<VolunteerForgot>) => ({
|
||||
readyStatus: "success",
|
||||
entity: payload,
|
||||
}),
|
||||
getFailure: (_, { payload }: PayloadAction<string>) => ({
|
||||
readyStatus: "failure",
|
||||
error: payload,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
export default volunteerForgotSlice.reducer
|
||||
export const { getRequesting, getSuccess, getFailure } = volunteerForgotSlice.actions
|
||||
|
||||
export const fetchVolunteerForgot = elementFetch(
|
||||
volunteerForgot,
|
||||
getRequesting,
|
||||
getSuccess,
|
||||
getFailure
|
||||
)
|
@@ -11,7 +11,7 @@ export const initialState: StateVolunteer = {
|
||||
}
|
||||
|
||||
const volunteerLoginSlice = createSlice({
|
||||
name: "volunteer",
|
||||
name: "volunteerLogin",
|
||||
initialState,
|
||||
reducers: {
|
||||
getRequesting: (_) => ({
|
||||
|
Reference in New Issue
Block a user