@ -1,6 +1,10 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useApolloClient } from '@apollo/client';
|
import { useApolloClient } from '@apollo/client';
|
||||||
import { useRecoilState } from 'recoil';
|
import {
|
||||||
|
snapshot_UNSTABLE,
|
||||||
|
useGotoRecoilSnapshot,
|
||||||
|
useRecoilState,
|
||||||
|
} from 'recoil';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
useChallengeMutation,
|
useChallengeMutation,
|
||||||
@ -24,6 +28,8 @@ export const useAuth = () => {
|
|||||||
|
|
||||||
const client = useApolloClient();
|
const client = useApolloClient();
|
||||||
|
|
||||||
|
const goToRecoilSnapshot = useGotoRecoilSnapshot();
|
||||||
|
|
||||||
const handleChallenge = useCallback(
|
const handleChallenge = useCallback(
|
||||||
async (email: string, password: string) => {
|
async (email: string, password: string) => {
|
||||||
const challengeResult = await challenge({
|
const challengeResult = await challenge({
|
||||||
@ -93,12 +99,13 @@ export const useAuth = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const handleSignOut = useCallback(() => {
|
const handleSignOut = useCallback(() => {
|
||||||
|
goToRecoilSnapshot(snapshot_UNSTABLE());
|
||||||
setTokenPair(null);
|
setTokenPair(null);
|
||||||
setCurrentUser(null);
|
setCurrentUser(null);
|
||||||
client.clearStore().then(() => {
|
client.clearStore().then(() => {
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
});
|
});
|
||||||
}, [setTokenPair, client, setCurrentUser]);
|
}, [goToRecoilSnapshot, setTokenPair, setCurrentUser, client]);
|
||||||
|
|
||||||
const handleCredentialsSignUp = useCallback(
|
const handleCredentialsSignUp = useCallback(
|
||||||
async (email: string, password: string, workspaceInviteHash?: string) => {
|
async (email: string, password: string, workspaceInviteHash?: string) => {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { SubmitHandler, useForm } from 'react-hook-form';
|
import { SubmitHandler, useForm } from 'react-hook-form';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { yupResolver } from '@hookform/resolvers/yup';
|
import { yupResolver } from '@hookform/resolvers/yup';
|
||||||
@ -71,12 +71,17 @@ export const useSignInUp = () => {
|
|||||||
mode: 'onChange',
|
mode: 'onChange',
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
exist: false,
|
exist: false,
|
||||||
email: isSignInPrefilled ? 'tim@apple.dev' : '',
|
|
||||||
password: isSignInPrefilled ? 'Applecar2025' : '',
|
|
||||||
},
|
},
|
||||||
resolver: yupResolver(validationSchema),
|
resolver: yupResolver(validationSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isSignInPrefilled) {
|
||||||
|
form.setValue('email', 'tim@apple.dev');
|
||||||
|
form.setValue('password', 'Applecar2025');
|
||||||
|
}
|
||||||
|
}, [form, isSignInPrefilled]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
signInWithCredentials,
|
signInWithCredentials,
|
||||||
signUpWithCredentials,
|
signUpWithCredentials,
|
||||||
|
|||||||
@ -1,13 +1,8 @@
|
|||||||
import { getOperationName } from '@apollo/client/utilities';
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
import { useRecoilCallback } from 'recoil';
|
|
||||||
|
|
||||||
import { RecoilScopeContext } from '@/types/RecoilScopeContext';
|
import { RecoilScopeContext } from '@/types/RecoilScopeContext';
|
||||||
import { savedBoardCardFieldsFamilyState } from '@/ui/board/states/savedBoardCardFieldsFamilyState';
|
|
||||||
import { savedTableColumnsFamilyState } from '@/ui/table/states/savedTableColumnsFamilyState';
|
|
||||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||||
import { currentViewIdScopedState } from '@/ui/view-bar/states/currentViewIdScopedState';
|
import { currentViewIdScopedState } from '@/ui/view-bar/states/currentViewIdScopedState';
|
||||||
import { savedFiltersFamilyState } from '@/ui/view-bar/states/savedFiltersFamilyState';
|
|
||||||
import { savedSortsFamilyState } from '@/ui/view-bar/states/savedSortsFamilyState';
|
|
||||||
import { viewsScopedState } from '@/ui/view-bar/states/viewsScopedState';
|
import { viewsScopedState } from '@/ui/view-bar/states/viewsScopedState';
|
||||||
import type { View } from '@/ui/view-bar/types/View';
|
import type { View } from '@/ui/view-bar/types/View';
|
||||||
import {
|
import {
|
||||||
@ -77,19 +72,6 @@ export const useViews = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleResetSavedViews = useRecoilCallback(
|
|
||||||
({ reset }) =>
|
|
||||||
() => {
|
|
||||||
views.forEach((view) => {
|
|
||||||
reset(savedBoardCardFieldsFamilyState(view.id));
|
|
||||||
reset(savedTableColumnsFamilyState(view.id));
|
|
||||||
reset(savedFiltersFamilyState(view.id));
|
|
||||||
reset(savedSortsFamilyState(view.id));
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[views],
|
|
||||||
);
|
|
||||||
|
|
||||||
const { loading } = useGetViewsQuery({
|
const { loading } = useGetViewsQuery({
|
||||||
variables: {
|
variables: {
|
||||||
where: {
|
where: {
|
||||||
@ -108,19 +90,6 @@ export const useViews = ({
|
|||||||
if (!nextViews.length) return;
|
if (!nextViews.length) return;
|
||||||
|
|
||||||
if (!currentViewId) return setCurrentViewId(nextViews[0].id);
|
if (!currentViewId) return setCurrentViewId(nextViews[0].id);
|
||||||
|
|
||||||
const currentViewExists = nextViews.some(
|
|
||||||
(view) => view.id === currentViewId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (currentViewExists) return;
|
|
||||||
|
|
||||||
// currentView does not exist in the list = the user has switched workspaces
|
|
||||||
// and currentViewId is outdated.
|
|
||||||
// Select the first view in the list.
|
|
||||||
setCurrentViewId(nextViews[0].id);
|
|
||||||
// Reset outdated view recoil states.
|
|
||||||
handleResetSavedViews();
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user