refactor: remove get-current-user GQL query

This commit is contained in:
Rıdvan Akca
2024-03-13 12:36:11 +03:00
parent 1e868dc802
commit 082e905014
9 changed files with 20 additions and 123 deletions

View File

@@ -14,7 +14,8 @@ import useCurrentUser from 'hooks/useCurrentUser';
function DeleteAccountDialog(props) {
const [deleteCurrentUser] = useMutation(DELETE_CURRENT_USER);
const formatMessage = useFormatMessage();
const { data: currentUser } = useCurrentUser();
const { data } = useCurrentUser();
const currentUser = data?.data;
const authentication = useAuthentication();
const navigate = useNavigate();
@@ -24,7 +25,7 @@ function DeleteAccountDialog(props) {
authentication.updateToken('');
await apolloClient.clearStore();
navigate(URLS.LOGIN);
}, [deleteCurrentUser, currentUser?.data]);
}, [deleteCurrentUser, currentUser]);
return (
<ConfirmationDialog

View File

@@ -7,7 +7,8 @@ import useCurrentUser from 'hooks/useCurrentUser';
const Chatwoot = ({ ready }) => {
const theme = useTheme();
const { data: currentUser } = useCurrentUser();
const { data } = useCurrentUser();
const currentUser = data?.data;
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('md'));
React.useEffect(function initiateChatwoot() {
@@ -24,17 +25,17 @@ const Chatwoot = ({ ready }) => {
React.useEffect(
function initiateUser() {
if (!currentUser?.data?.id || !ready) return;
window.$chatwoot.setUser(currentUser.data?.id, {
email: currentUser?.data?.email,
name: currentUser?.data?.fullName,
if (!currentUser?.id || !ready) return;
window.$chatwoot.setUser(currentUser.id, {
email: currentUser.email,
name: currentUser.fullName,
});
if (!matchSmallScreens) {
window.$chatwoot.toggleBubbleVisibility('show');
}
},
[currentUser?.data, ready, matchSmallScreens],
[currentUser, ready, matchSmallScreens],
);
React.useLayoutEffect(
function hideChatwoot() {

View File

@@ -21,7 +21,8 @@ import usePaddle from 'hooks/usePaddle.ee';
export default function UpgradeFreeTrial() {
const { data: plans, isLoading: isPaymentPlansLoading } = usePaymentPlans();
const { data: currentUser } = useCurrentUser();
const { data } = useCurrentUser();
const currentUser = data?.data;
const { loaded: paddleLoaded } = usePaddle();
const [selectedIndex, setSelectedIndex] = React.useState(0);
const selectedPlan = plans?.data?.[selectedIndex];
@@ -30,13 +31,13 @@ export default function UpgradeFreeTrial() {
const handleCheckout = React.useCallback(() => {
window.Paddle.Checkout?.open({
product: selectedPlan.productId,
email: currentUser?.data?.email,
email: currentUser?.email,
passthrough: JSON.stringify({
id: currentUser?.data?.id,
email: currentUser?.data?.email,
id: currentUser?.id,
email: currentUser?.email,
}),
});
}, [selectedPlan, currentUser?.data]);
}, [selectedPlan, currentUser]);
if (isPaymentPlansLoading || !plans?.data?.length) return null;

View File

@@ -1,20 +0,0 @@
import { gql } from '@apollo/client';
export const GET_CURRENT_USER = gql`
query GetCurrentUser {
getCurrentUser {
id
fullName
email
role {
id
isAdmin
}
permissions {
id
action
subject
conditions
}
}
}
`;

View File

@@ -40,7 +40,8 @@ function ProfileSettings() {
const [showDeleteAccountConfirmation, setShowDeleteAccountConfirmation] =
React.useState(false);
const enqueueSnackbar = useEnqueueSnackbar();
const { data: currentUser } = useCurrentUser();
const { data } = useCurrentUser();
const currentUser = data?.data;
const formatMessage = useFormatMessage();
const [updateCurrentUser] = useMutation(UPDATE_CURRENT_USER);
@@ -62,7 +63,7 @@ function ProfileSettings() {
optimisticResponse: {
updateCurrentUser: {
__typename: 'User',
id: currentUser?.data?.id,
id: currentUser?.id,
fullName,
email,
},
@@ -87,7 +88,7 @@ function ProfileSettings() {
<Grid item xs={12} justifyContent="flex-end">
<StyledForm
defaultValues={{
...currentUser?.data,
...currentUser,
password: '',
confirmPassword: '',
}}