remove unnecessary fetches of api (#960)
* skip repeating fetch of user on session changes * fix some issues on integrationspull/961/head
parent
c2c37b701e
commit
59e25ad04e
|
@ -37,15 +37,8 @@ import { useViewerI18n } from "./I18nLanguageHandler";
|
|||
import Logo from "./Logo";
|
||||
|
||||
function useMeQuery() {
|
||||
const [session] = useSession();
|
||||
const meQuery = trpc.useQuery(["viewer.me"]);
|
||||
|
||||
useEffect(() => {
|
||||
// refetch if sesion changes
|
||||
meQuery.refetch();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [session]);
|
||||
|
||||
return meQuery;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Image from "next/image";
|
||||
import { ReactNode, useEffect, useState } from "react";
|
||||
import { Fragment, ReactNode, useState } from "react";
|
||||
import { useMutation } from "react-query";
|
||||
|
||||
import { QueryCell } from "@lib/QueryCell";
|
||||
|
@ -56,13 +56,15 @@ function ConnectIntegration(props: { type: string; render: (renderProps: ButtonB
|
|||
window.location.href = json.url;
|
||||
setIsLoading(true);
|
||||
});
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
|
||||
// refetch intergrations when modal closes
|
||||
const [isModalOpen, _setIsModalOpen] = useState(false);
|
||||
const utils = trpc.useContext();
|
||||
useEffect(() => {
|
||||
|
||||
const setIsModalOpen: typeof _setIsModalOpen = (v) => {
|
||||
_setIsModalOpen(v);
|
||||
// refetch intergrations on modal toggles
|
||||
|
||||
utils.invalidateQueries(["viewer.integrations"]);
|
||||
}, [isModalOpen, utils]);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -340,8 +342,8 @@ export default function IntegrationsPage() {
|
|||
{data.connectedCalendars.length > 0 && (
|
||||
<>
|
||||
<List>
|
||||
{data.connectedCalendars.map((item, index) => (
|
||||
<li key={index}>
|
||||
{data.connectedCalendars.map((item) => (
|
||||
<Fragment key={item.credentialId}>
|
||||
{item.calendars ? (
|
||||
<IntegrationListItem
|
||||
{...item.integration}
|
||||
|
@ -385,7 +387,7 @@ export default function IntegrationsPage() {
|
|||
}
|
||||
/>
|
||||
)}
|
||||
</li>
|
||||
</Fragment>
|
||||
))}
|
||||
</List>
|
||||
<ShellSubHeading
|
||||
|
|
Loading…
Reference in New Issue