Fix comment creation bug (#371)
This commit is contained in:
@ -1,26 +1,13 @@
|
|||||||
import { useEffect } from 'react';
|
|
||||||
import jwt from 'jwt-decode';
|
import jwt from 'jwt-decode';
|
||||||
import { useRecoilState } from 'recoil';
|
|
||||||
|
|
||||||
import { useGetCurrentUserQuery } from '~/generated/graphql';
|
import { AuthTokenPair, useGetCurrentUserQuery } from '~/generated/graphql';
|
||||||
|
|
||||||
import { currentUserState } from '../states/currentUserState';
|
export function useFetchCurrentUser(tokenPair: AuthTokenPair | null) {
|
||||||
import { tokenPairState } from '../states/tokenPairState';
|
|
||||||
|
|
||||||
export function useFetchCurrentUser() {
|
|
||||||
const [, setCurrentUser] = useRecoilState(currentUserState);
|
|
||||||
const [tokenPair] = useRecoilState(tokenPairState);
|
|
||||||
const userId = tokenPair?.accessToken.token
|
const userId = tokenPair?.accessToken.token
|
||||||
? jwt<{ sub: string }>(tokenPair.accessToken.token).sub
|
? jwt<{ sub: string }>(tokenPair.accessToken.token).sub
|
||||||
: null;
|
: null;
|
||||||
const { data } = useGetCurrentUserQuery({
|
const { data } = useGetCurrentUserQuery({
|
||||||
variables: { uuid: userId },
|
variables: { uuid: userId },
|
||||||
});
|
});
|
||||||
const user = data?.users?.[0];
|
return data?.users?.[0];
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (user) {
|
|
||||||
setCurrentUser(user);
|
|
||||||
}
|
|
||||||
}, [user, setCurrentUser]);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ const cookieStorageEffect =
|
|||||||
(key: string): AtomEffect<AuthTokenPair | null> =>
|
(key: string): AtomEffect<AuthTokenPair | null> =>
|
||||||
({ setSelf, onSet }) => {
|
({ setSelf, onSet }) => {
|
||||||
const savedValue = cookieStorage.getItem(key);
|
const savedValue = cookieStorage.getItem(key);
|
||||||
if (savedValue != null) {
|
if (savedValue != null && JSON.parse(savedValue)['accessToken']) {
|
||||||
setSelf(JSON.parse(savedValue));
|
setSelf(JSON.parse(savedValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ export function DropdownMenuCheckableItem({
|
|||||||
return (
|
return (
|
||||||
<DropdownMenuCheckableItemContainer onClick={handleClick}>
|
<DropdownMenuCheckableItemContainer onClick={handleClick}>
|
||||||
<StyledLeftContainer>
|
<StyledLeftContainer>
|
||||||
<Checkbox onChange={onChange} id={id} name={id} checked={checked} />
|
<Checkbox id={id} name={id} checked={checked} />
|
||||||
<StyledChildrenContainer>{children}</StyledChildrenContainer>
|
<StyledChildrenContainer>{children}</StyledChildrenContainer>
|
||||||
</StyledLeftContainer>
|
</StyledLeftContainer>
|
||||||
</DropdownMenuCheckableItemContainer>
|
</DropdownMenuCheckableItemContainer>
|
||||||
|
|||||||
@ -1,9 +1,22 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
import { useFetchCurrentUser } from '@/auth/hooks/useFetchCurrentUser';
|
import { useFetchCurrentUser } from '@/auth/hooks/useFetchCurrentUser';
|
||||||
|
import { currentUserState } from '@/auth/states/currentUserState';
|
||||||
|
import { tokenPairState } from '@/auth/states/tokenPairState';
|
||||||
|
|
||||||
export const UserProvider: React.FC<React.PropsWithChildren> = ({
|
export const UserProvider: React.FC<React.PropsWithChildren> = ({
|
||||||
children,
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
useFetchCurrentUser();
|
const [, setCurrentUser] = useRecoilState(currentUserState);
|
||||||
|
const [tokenPair] = useRecoilState(tokenPairState);
|
||||||
|
const user = useFetchCurrentUser(tokenPair);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (user) {
|
||||||
|
setCurrentUser(user);
|
||||||
|
}
|
||||||
|
}, [setCurrentUser, user]);
|
||||||
|
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -63,11 +63,13 @@ export class AbilityFactory {
|
|||||||
can(AbilityAction.Read, 'Company', { workspaceId: workspace.id });
|
can(AbilityAction.Read, 'Company', { workspaceId: workspace.id });
|
||||||
can(AbilityAction.Create, 'Company');
|
can(AbilityAction.Create, 'Company');
|
||||||
can(AbilityAction.Update, 'Company', { workspaceId: workspace.id });
|
can(AbilityAction.Update, 'Company', { workspaceId: workspace.id });
|
||||||
|
can(AbilityAction.Delete, 'Company', { workspaceId: workspace.id });
|
||||||
|
|
||||||
// Person
|
// Person
|
||||||
can(AbilityAction.Read, 'Person', { workspaceId: workspace.id });
|
can(AbilityAction.Read, 'Person', { workspaceId: workspace.id });
|
||||||
can(AbilityAction.Create, 'Person');
|
can(AbilityAction.Create, 'Person');
|
||||||
can(AbilityAction.Update, 'Person', { workspaceId: workspace.id });
|
can(AbilityAction.Update, 'Person', { workspaceId: workspace.id });
|
||||||
|
can(AbilityAction.Delete, 'Person', { workspaceId: workspace.id });
|
||||||
|
|
||||||
// RefreshToken
|
// RefreshToken
|
||||||
cannot(AbilityAction.Manage, 'RefreshToken');
|
cannot(AbilityAction.Manage, 'RefreshToken');
|
||||||
|
|||||||
Reference in New Issue
Block a user