(() => {
if (!appAllowed) {
return [];
}
return [
{
key: 'cache',
label: t('Clear cache'),
onClick: async () => {
await api.resource('app').clearCache();
window.location.reload();
},
},
{
key: 'reboot',
label: t('Restart application'),
onClick: async () => {
modal.confirm({
title: t('Restart application'),
// content: t('The will interrupt service, it may take a few seconds to restart. Are you sure to continue?'),
okText: t('Restart'),
okButtonProps: {
danger: true,
},
onOk: async () => {
await api.resource('app').restart();
},
});
},
},
{
key: 'divider_4',
type: 'divider',
},
];
}, [api, appAllowed, check, modal, t]);
useEffect(() => {
const items = [
nickname,
{
key: 'divider_1',
type: 'divider',
},
editProfile,
changePassword,
{
key: 'divider_2',
type: 'divider',
},
switchRole,
{
key: 'divider_3',
type: 'divider',
},
...controlApp,
{
key: 'signout',
label: t('Sign out'),
onClick: async () => {
const { data } = await api.auth.signOut();
if (data?.data?.redirect) {
window.location.href = data.data.redirect;
} else {
navigate(`/signin?redirect=${encodeURIComponent(redirectUrl)}`);
}
},
},
];
items.forEach((item) => {
if (item) {
addMenuItem(item);
}
});
if (languageSettings) {
addMenuItem(languageSettings, { before: 'divider_3' });
}
}, [
addMenuItem,
api.auth,
changePassword,
controlApp,
editProfile,
languageSettings,
navigate,
redirectUrl,
switchRole,
t,
nickname,
]);
return ;
};
export const DropdownVisibleContext = createContext(null);
DropdownVisibleContext.displayName = 'DropdownVisibleContext';
export const CurrentUser = () => {
const [visible, setVisible] = useState(false);
const { token } = useToken();
return (
{
setVisible(visible);
}}
dropdownRender={() => {
return ;
}}
>
);
};