[#32] changed how userinfo is filled
This commit is contained in:
committed by
Benoit TELLIER
parent
290c7f301b
commit
b9d2a16984
@@ -2,7 +2,7 @@ import { useEffect, useRef } from "react";
|
||||
import { Callback } from "./oidcAuth";
|
||||
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
||||
import { push } from "redux-first-history";
|
||||
import { getOpenPaasUserIdAsync, setTokens, setUserData } from "./userSlice";
|
||||
import { getOpenPaasUserDataAsync, setTokens, setUserData } from "./userSlice";
|
||||
import { Loading } from "../../components/Loading/Loading";
|
||||
import { getCalendarsListAsync } from "../Calendars/CalendarSlice";
|
||||
|
||||
@@ -22,7 +22,7 @@ export function CallbackResume() {
|
||||
const data = await Callback(saved?.code_verifier, saved?.state);
|
||||
dispatch(setUserData(data?.userinfo));
|
||||
dispatch(setTokens(data?.tokenSet));
|
||||
dispatch(getOpenPaasUserIdAsync());
|
||||
dispatch(getOpenPaasUserDataAsync());
|
||||
dispatch(getCalendarsListAsync());
|
||||
|
||||
sessionStorage.removeItem("redirectState");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { api } from "../../utils/apiUtils";
|
||||
|
||||
export default async function getOpenPaasUserId() {
|
||||
export default async function getOpenPaasUser() {
|
||||
const user = await api.get(`api/user`).json();
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||
import { userData, userOrganiser } from "./userDataTypes";
|
||||
import getOpenPaasUserId from "./userAPI";
|
||||
import getOpenPaasUser from "./userAPI";
|
||||
|
||||
export const getOpenPaasUserIdAsync = createAsyncThunk<string>(
|
||||
"user/getOpenPaasUserId",
|
||||
export const getOpenPaasUserDataAsync = createAsyncThunk<any>(
|
||||
"user/getOpenPaasUserData",
|
||||
async () => {
|
||||
const user = (await getOpenPaasUserId()) as Record<string, string>;
|
||||
const user = (await getOpenPaasUser()) as Record<string, string>;
|
||||
|
||||
return user.id;
|
||||
return user;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -32,8 +32,18 @@ export const userSlice = createSlice({
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
builder.addCase(getOpenPaasUserIdAsync.fulfilled, (state, action) => {
|
||||
state.userData.openpaasId = action.payload;
|
||||
builder.addCase(getOpenPaasUserDataAsync.fulfilled, (state, action) => {
|
||||
state.userData.name = action.payload.firstname;
|
||||
state.userData.family_name = action.payload.lastname;
|
||||
state.userData.openpaasId = action.payload.id;
|
||||
if (!state.organiserData) {
|
||||
state.organiserData = {} as userOrganiser;
|
||||
}
|
||||
state.organiserData.cn = `${action.payload.firstname} ${action.payload.lastname}`;
|
||||
if (action.payload.preferredEmail) {
|
||||
state.organiserData.cal_address = `mailto:${action.payload.preferredEmail}`;
|
||||
state.userData.email = action.payload.preferredEmail;
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user