refactor: rewrite useCurrentUser with RQ

This commit is contained in:
Rıdvan Akca
2024-03-13 12:33:31 +03:00
parent c849afbc11
commit 1e868dc802
6 changed files with 56 additions and 22 deletions

View File

@@ -1,34 +1,40 @@
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: currentUser } = useCurrentUser();
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;
window.$chatwoot.setUser(currentUser.id, {
email: currentUser.email,
name: currentUser.fullName,
if (!currentUser?.data?.id || !ready) return;
window.$chatwoot.setUser(currentUser.data?.id, {
email: currentUser?.data?.email,
name: currentUser?.data?.fullName,
});
if (!matchSmallScreens) {
window.$chatwoot.toggleBubbleVisibility('show');
}
},
[currentUser, ready, matchSmallScreens],
[currentUser?.data, ready, matchSmallScreens],
);
React.useLayoutEffect(
function hideChatwoot() {
@@ -40,6 +46,7 @@ const Chatwoot = ({ ready }) => {
},
[matchSmallScreens],
);
return <React.Fragment />;
};
export default Chatwoot;