fix: Flakyness on pages that use a hard refresh (#16752)

* fix: Flakyness on pages that use a hard refres

Signed-off-by: zomars <[email protected]>

* Update Shell.tsx

---------

Signed-off-by: zomars <[email protected]>
This commit is contained in:
Omar López authored and GitHub committed 2024-09-21 03:41:10 +00:00
1 parent 1a60afad7a
commit 6dd8812a19
9 files changed
+21 -16

No files matched your search

@@ -9,6 +9,7 @@ import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
import { getTeamUrlSync } from "@calcom/lib/getBookerUrl/client";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useRefreshData } from "@calcom/lib/hooks/useRefreshData";
import { MembershipRole } from "@calcom/prisma/enums";
import type { RouterOutputs } from "@calcom/trpc/react";
import { trpc } from "@calcom/trpc/react";
@@ -51,6 +52,7 @@ export default function TeamListItem(props: Props) {
const showDialog = searchParams?.get("inviteModal") === "true";
const [openMemberInvitationModal, setOpenMemberInvitationModal] = useState(showDialog);
const [openInviteLinkSettingsModal, setOpenInviteLinkSettingsModal] = useState(false);
const refreshData = useRefreshData();
const acceptOrLeaveMutation = trpc.viewer.teams.acceptOrLeave.useMutation({
onSuccess: (_data, variables) => {
@@ -64,7 +66,7 @@ export default function TeamListItem(props: Props) {
const isDifferentOrg = team.isOrganization && team.id !== userOrganizationId;
// If the user team being accepted is a sub-team of different organization or the different organization itself then page must be reloaded to let the session change reflect reliably everywhere.
if (variables.accept && (isSubTeamOfDifferentOrg || isDifferentOrg)) {
window.location.reload();
refreshData();
}
},
});
+3 -1
View File
@@ -56,6 +56,7 @@ import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl";
import { useCopy } from "@calcom/lib/hooks/useCopy";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { ButtonState, useNotifications } from "@calcom/lib/hooks/useNotifications";
import { useRefreshData } from "@calcom/lib/hooks/useRefreshData";
import useTheme from "@calcom/lib/hooks/useTheme";
import { isKeyInObject } from "@calcom/lib/isKeyInObject";
import { localStorage } from "@calcom/lib/webstorage";
@@ -1286,6 +1287,7 @@ function ProfileDropdown() {
const { update, data: sessionData } = useSession();
const { data } = trpc.viewer.me.useQuery();
const [menuOpen, setMenuOpen] = useState(false);
const refreshData = useRefreshData();
if (!data || !ENABLE_PROFILE_SWITCHER || !sessionData) {
return null;
@@ -1349,7 +1351,7 @@ function ProfileDropdown() {
update({
upId: option.value,
}).then(() => {
window.location.reload();
refreshData();
});
}}
className={classNames("flex w-full", isSelected ? "bg-subtle text-emphasis" : "")}>
+12
View File
@@ -0,0 +1,12 @@
import { usePathname, useSearchParams } from "next/navigation";
import { useMemo } from "react";
export function useAsPath() {
const pathname = usePathname();
const searchParams = useSearchParams();
const asPath = useMemo(
() => `${pathname}${searchParams ? `?${searchParams.toString()}` : ""}`,
[pathname, searchParams]
);
return asPath;
}
+13
View File
@@ -0,0 +1,13 @@
import { useRouter } from "next/navigation";
import { useAsPath } from "./useAsPath";
/** @see https://www.joshwcomeau.com/nextjs/refreshing-server-side-props/ */
export function useRefreshData() {
const router = useRouter();
const asPath = useAsPath();
const refreshData = () => {
router.replace(asPath);
};
return refreshData;
}