Merge pull request #1717 from automatisch/AUT-829

refactor: rewrite useCurrentUser with RQ
This commit is contained in:
Ali BARIN
2024-03-15 14:02:09 +01:00
committed by GitHub
11 changed files with 52 additions and 121 deletions

View File

@@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import * as React from 'react';
import { useNavigate } from 'react-router-dom';
import { useMutation } from '@apollo/client';
import * as URLS from 'config/urls';
import ConfirmationDialog from 'components/ConfirmationDialog';
import apolloClient from 'graphql/client';
@@ -13,15 +14,19 @@ import useCurrentUser from 'hooks/useCurrentUser';
function DeleteAccountDialog(props) {
const [deleteCurrentUser] = useMutation(DELETE_CURRENT_USER);
const formatMessage = useFormatMessage();
const currentUser = useCurrentUser();
const { data } = useCurrentUser();
const currentUser = data?.data;
const authentication = useAuthentication();
const navigate = useNavigate();
const handleConfirm = React.useCallback(async () => {
await deleteCurrentUser();
authentication.updateToken('');
await apolloClient.clearStore();
navigate(URLS.LOGIN);
}, [deleteCurrentUser, currentUser]);
return (
<ConfirmationDialog
title={formatMessage('deleteAccountDialog.title')}

View File

@@ -1,22 +1,28 @@
import * as React from 'react';
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import appConfig from 'config/app';
import useCurrentUser from 'hooks/useCurrentUser';
const Chatwoot = ({ ready }) => {
const theme = useTheme();
const currentUser = useCurrentUser();
const { data } = useCurrentUser();
const currentUser = data?.data;
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('md'));
React.useEffect(function initiateChatwoot() {
window.chatwootSDK.run({
websiteToken: 'EFyq5MTsvS7XwUrwSH36VskT',
baseUrl: appConfig.chatwootBaseUrl,
});
return function removeChatwoot() {
window.$chatwoot.reset();
window.$chatwoot.toggleBubbleVisibility('hide');
};
}, []);
React.useEffect(
function initiateUser() {
if (!currentUser?.id || !ready) return;
@@ -24,6 +30,7 @@ const Chatwoot = ({ ready }) => {
email: currentUser.email,
name: currentUser.fullName,
});
if (!matchSmallScreens) {
window.$chatwoot.toggleBubbleVisibility('show');
}
@@ -40,6 +47,7 @@ const Chatwoot = ({ ready }) => {
},
[matchSmallScreens],
);
return <React.Fragment />;
};
export default Chatwoot;

View File

@@ -21,7 +21,8 @@ import usePaddle from 'hooks/usePaddle.ee';
export default function UpgradeFreeTrial() {
const { data: plans, isLoading: isPaymentPlansLoading } = usePaymentPlans();
const 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,10 +31,10 @@ export default function UpgradeFreeTrial() {
const handleCheckout = React.useCallback(() => {
window.Paddle.Checkout?.open({
product: selectedPlan.productId,
email: currentUser.email,
email: currentUser?.email,
passthrough: JSON.stringify({
id: currentUser.id,
email: currentUser.email,
id: currentUser?.id,
email: currentUser?.email,
}),
});
}, [selectedPlan, currentUser]);