fix(user): guard openpaasId access during initial render\n\n- Use optional chaining across components reading userData.openpaasId\n- Prevent F5 crash when user data not yet hydrated\n- Cleanup unused imports
This commit is contained in:
@@ -56,7 +56,7 @@ export default function CalendarApp() {
|
|||||||
|
|
||||||
const calendars = useAppSelector((state) => state.calendars.list);
|
const calendars = useAppSelector((state) => state.calendars.list);
|
||||||
const pending = useAppSelector((state) => state.calendars.pending);
|
const pending = useAppSelector((state) => state.calendars.pending);
|
||||||
const userId = useAppSelector((state) => state.user.userData.openpaasId);
|
const userId = useAppSelector((state) => state.user.userData?.openpaasId) ?? "";
|
||||||
const selectPersonnalCalendars = createSelector(
|
const selectPersonnalCalendars = createSelector(
|
||||||
(state) => state.calendars,
|
(state) => state.calendars,
|
||||||
(calendars) =>
|
(calendars) =>
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { Calendars } from "../../features/Calendars/CalendarTypes";
|
|||||||
import MoreVertIcon from "@mui/icons-material/MoreVert";
|
import MoreVertIcon from "@mui/icons-material/MoreVert";
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
import Checkbox from "@mui/material/Checkbox";
|
import Checkbox from "@mui/material/Checkbox";
|
||||||
import Button from "@mui/material/Button";
|
|
||||||
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
||||||
|
|
||||||
function CalendarAccordion({
|
function CalendarAccordion({
|
||||||
@@ -81,7 +80,7 @@ export default function CalendarSelection({
|
|||||||
selectedCalendars: string[];
|
selectedCalendars: string[];
|
||||||
setSelectedCalendars: Function;
|
setSelectedCalendars: Function;
|
||||||
}) {
|
}) {
|
||||||
const userId = useAppSelector((state) => state.user.userData.openpaasId);
|
const userId = useAppSelector((state) => state.user.userData?.openpaasId) ?? "";
|
||||||
const calendars = useAppSelector((state) => state.calendars.list);
|
const calendars = useAppSelector((state) => state.calendars.list);
|
||||||
|
|
||||||
const personnalCalendars = Object.keys(calendars).filter(
|
const personnalCalendars = Object.keys(calendars).filter(
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ function CalendarPopover({
|
|||||||
}) {
|
}) {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const userId =
|
const userId =
|
||||||
useAppSelector((state) => state.user.userData.openpaasId) ?? "";
|
useAppSelector((state) => state.user.userData?.openpaasId) ?? "";
|
||||||
const [name, setName] = useState(calendar?.name ?? "");
|
const [name, setName] = useState(calendar?.name ?? "");
|
||||||
const [description, setDescription] = useState(calendar?.description ?? "");
|
const [description, setDescription] = useState(calendar?.description ?? "");
|
||||||
const [color, setColor] = useState(calendar?.color ?? "");
|
const [color, setColor] = useState(calendar?.color ?? "");
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export default function EventDisplayModal({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const userPersonnalCalendars: Calendars[] = calendars.filter(
|
const userPersonnalCalendars: Calendars[] = calendars.filter(
|
||||||
(c) => c.id?.split("/")[0] === user.userData.openpaasId
|
(c) => c.id?.split("/")[0] === user.userData?.openpaasId
|
||||||
);
|
);
|
||||||
|
|
||||||
// Form state
|
// Form state
|
||||||
@@ -97,7 +97,7 @@ export default function EventDisplayModal({
|
|||||||
const [timezone, setTimezone] = useState(event?.timezone ?? "UTC");
|
const [timezone, setTimezone] = useState(event?.timezone ?? "UTC");
|
||||||
const [newCalId, setNewCalId] = useState(event?.calId);
|
const [newCalId, setNewCalId] = useState(event?.calId);
|
||||||
const [calendarid, setCalendarid] = useState(
|
const [calendarid, setCalendarid] = useState(
|
||||||
calId.split("/")[0] === user.userData.openpaasId
|
calId.split("/")[0] === user.userData?.openpaasId
|
||||||
? userPersonnalCalendars.findIndex((cal) => cal.id === calId)
|
? userPersonnalCalendars.findIndex((cal) => cal.id === calId)
|
||||||
: calendars.findIndex((cal) => cal.id === calId)
|
: calendars.findIndex((cal) => cal.id === calId)
|
||||||
);
|
);
|
||||||
@@ -198,7 +198,7 @@ export default function EventDisplayModal({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const calList =
|
const calList =
|
||||||
calId.split("/")[0] === user.userData.openpaasId
|
calId.split("/")[0] === user.userData?.openpaasId
|
||||||
? Object.keys(userPersonnalCalendars).map((calendar, index) => (
|
? Object.keys(userPersonnalCalendars).map((calendar, index) => (
|
||||||
<MenuItem key={index} value={index}>
|
<MenuItem key={index} value={index}>
|
||||||
<Typography variant="body2">
|
<Typography variant="body2">
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ function EventPopover({
|
|||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const organizer = useAppSelector((state) => state.user.organiserData);
|
const organizer = useAppSelector((state) => state.user.organiserData);
|
||||||
const userId = useAppSelector((state) => state.user.userData.openpaasId);
|
const userId = useAppSelector((state) => state.user.userData?.openpaasId) ?? "";
|
||||||
const selectPersonnalCalendars = createSelector(
|
const selectPersonnalCalendars = createSelector(
|
||||||
(state) => state.calendars,
|
(state) => state.calendars,
|
||||||
(calendars) =>
|
(calendars) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user