mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-29 15:25:45 +03:00
Fix comment creation bug (#371)
This commit is contained in:
parent
31145c5518
commit
9c21975d2b
@ -1,26 +1,13 @@
|
||||
import { useEffect } from 'react';
|
||||
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';
|
||||
import { tokenPairState } from '../states/tokenPairState';
|
||||
|
||||
export function useFetchCurrentUser() {
|
||||
const [, setCurrentUser] = useRecoilState(currentUserState);
|
||||
const [tokenPair] = useRecoilState(tokenPairState);
|
||||
export function useFetchCurrentUser(tokenPair: AuthTokenPair | null) {
|
||||
const userId = tokenPair?.accessToken.token
|
||||
? jwt<{ sub: string }>(tokenPair.accessToken.token).sub
|
||||
: null;
|
||||
const { data } = useGetCurrentUserQuery({
|
||||
variables: { uuid: userId },
|
||||
});
|
||||
const user = data?.users?.[0];
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
setCurrentUser(user);
|
||||
}
|
||||
}, [user, setCurrentUser]);
|
||||
return data?.users?.[0];
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ const cookieStorageEffect =
|
||||
(key: string): AtomEffect<AuthTokenPair | null> =>
|
||||
({ setSelf, onSet }) => {
|
||||
const savedValue = cookieStorage.getItem(key);
|
||||
if (savedValue != null) {
|
||||
if (savedValue != null && JSON.parse(savedValue)['accessToken']) {
|
||||
setSelf(JSON.parse(savedValue));
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ export function DropdownMenuCheckableItem({
|
||||
return (
|
||||
<DropdownMenuCheckableItemContainer onClick={handleClick}>
|
||||
<StyledLeftContainer>
|
||||
<Checkbox onChange={onChange} id={id} name={id} checked={checked} />
|
||||
<Checkbox id={id} name={id} checked={checked} />
|
||||
<StyledChildrenContainer>{children}</StyledChildrenContainer>
|
||||
</StyledLeftContainer>
|
||||
</DropdownMenuCheckableItemContainer>
|
||||
|
@ -1,9 +1,22 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
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> = ({
|
||||
children,
|
||||
}) => {
|
||||
useFetchCurrentUser();
|
||||
const [, setCurrentUser] = useRecoilState(currentUserState);
|
||||
const [tokenPair] = useRecoilState(tokenPairState);
|
||||
const user = useFetchCurrentUser(tokenPair);
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
setCurrentUser(user);
|
||||
}
|
||||
}, [setCurrentUser, user]);
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
@ -63,11 +63,13 @@ export class AbilityFactory {
|
||||
can(AbilityAction.Read, 'Company', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Create, 'Company');
|
||||
can(AbilityAction.Update, 'Company', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Delete, 'Company', { workspaceId: workspace.id });
|
||||
|
||||
// Person
|
||||
can(AbilityAction.Read, 'Person', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Create, 'Person');
|
||||
can(AbilityAction.Update, 'Person', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Delete, 'Person', { workspaceId: workspace.id });
|
||||
|
||||
// RefreshToken
|
||||
cannot(AbilityAction.Manage, 'RefreshToken');
|
||||
|
Loading…
Reference in New Issue
Block a user