From b64593df90039239a2e09e1b4a700bc88c291a3e Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Thu, 28 Mar 2024 12:28:24 +0000 Subject: [PATCH] Solved a problem with the record page not being able to reload --- src/components/Low/Select.tsx | 53 ++++++++++++++++++++--------------- src/components/Navbar.tsx | 4 ++- src/pages/record.tsx | 4 +-- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/components/Low/Select.tsx b/src/components/Low/Select.tsx index d35b4076..4c336202 100644 --- a/src/components/Low/Select.tsx +++ b/src/components/Low/Select.tsx @@ -1,6 +1,6 @@ import clsx from "clsx"; import {ComponentProps, useEffect, useState} from "react"; -import ReactSelect from "react-select"; +import ReactSelect, {GroupBase, StylesConfig} from "react-select"; interface Option { [key: string]: any; @@ -16,9 +16,10 @@ interface Props { placeholder?: string; onChange: (value: Option | null) => void; isClearable?: boolean; + styles?: StylesConfig>; } -export default function Select({value, defaultValue, options, placeholder, disabled, onChange, isClearable}: Props) { +export default function Select({value, defaultValue, options, placeholder, disabled, onChange, styles, isClearable}: Props) { const [target, setTarget] = useState(); useEffect(() => { @@ -27,33 +28,39 @@ export default function Select({value, defaultValue, options, placeholder, disab return ( ({...base, zIndex: 9999}), - control: (styles) => ({ - ...styles, - paddingLeft: "4px", - border: "none", - outline: "none", - ":focus": { + styles={ + styles || { + menuPortal: (base) => ({...base, zIndex: 9999}), + control: (styles) => ({ + ...styles, + paddingLeft: "4px", + border: "none", outline: "none", - }, - }), - option: (styles, state) => ({ - ...styles, - backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white", - color: state.isFocused ? "black" : styles.color, - }), - }} + ":focus": { + outline: "none", + }, + }), + option: (styles, state) => ({ + ...styles, + backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white", + color: state.isFocused ? "black" : styles.color, + }), + } + } isDisabled={disabled} isClearable={isClearable} /> diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index e6a44605..4a2caf65 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -31,6 +31,8 @@ export default function Navbar({user, path, navDisabled = false, focusMode = fal const [disablePaymentPage, setDisablePaymentPage] = useState(true); const [isTicketOpen, setIsTicketOpen] = useState(false); + const router = useRouter(); + const disableNavigation = preventNavigation(navDisabled, focusMode); const expirationDateColor = (date: Date) => { @@ -59,7 +61,7 @@ export default function Navbar({user, path, navDisabled = false, focusMode = fal return ( <> setIsTicketOpen(false)} title="Submit a ticket"> - setIsTicketOpen(false)} /> + setIsTicketOpen(false)} /> {user && ( diff --git a/src/pages/record.tsx b/src/pages/record.tsx index 558da5a8..4bfef294 100644 --- a/src/pages/record.tsx +++ b/src/pages/record.tsx @@ -19,7 +19,7 @@ import Layout from "@/components/High/Layout"; import clsx from "clsx"; import {calculateBandScore} from "@/utils/score"; import {BsBook, BsClipboard, BsHeadphones, BsMegaphone, BsPen} from "react-icons/bs"; -import Select from "react-select"; +import Select from "@/components/Low/Select"; import useGroups from "@/hooks/useGroups"; import {shouldRedirectHome} from "@/utils/navigation.disabled"; import useAssignments from "@/hooks/useAssignments"; @@ -320,7 +320,6 @@ export default function History({user}: {user: User}) { options={users.map((x) => ({value: x.id, label: `${x.name} - ${x.email}`}))} defaultValue={{value: user.id, label: `${user.name} - ${user.email}`}} onChange={(value) => setStatsUserId(value?.value)} - menuPortalTarget={document?.body} styles={{ menuPortal: (base) => ({...base, zIndex: 9999}), option: (styles, state) => ({ @@ -338,7 +337,6 @@ export default function History({user}: {user: User}) { .map((x) => ({value: x.id, label: `${x.name} - ${x.email}`}))} defaultValue={{value: user.id, label: `${user.name} - ${user.email}`}} onChange={(value) => setStatsUserId(value?.value)} - menuPortalTarget={document?.body} styles={{ menuPortal: (base) => ({...base, zIndex: 9999}), option: (styles, state) => ({