2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

disable buttons if no email is set

This commit is contained in:
Matthias Mair
2025-01-20 22:34:27 +01:00
parent 0c86f2705f
commit 8be0a52930

View File

@ -75,6 +75,9 @@ function EmailSection() {
queryFn: () => queryFn: () =>
authApi(apiUrl(ApiEndpoints.auth_email)).then((res) => res.data.data) authApi(apiUrl(ApiEndpoints.auth_email)).then((res) => res.data.data)
}); });
const emailAvailable = useMemo(() => {
return data == undefined || data.length == 0;
}, [data]);
function runServerAction( function runServerAction(
action: 'post' | 'put' | 'delete' = 'post', action: 'post' | 'put' | 'delete' = 'post',
@ -96,7 +99,7 @@ function EmailSection() {
return ( return (
<Grid> <Grid>
<Grid.Col span={6}> <Grid.Col span={6}>
{data.length == 0 ? ( {emailAvailable ? (
<Alert <Alert
icon={<IconAlertCircle size='1rem' />} icon={<IconAlertCircle size='1rem' />}
title={t`Not configured`} title={t`Not configured`}
@ -161,13 +164,20 @@ function EmailSection() {
onClick={() => onClick={() =>
runServerAction('post', { email: value, primary: true }) runServerAction('post', { email: value, primary: true })
} }
disabled={emailAvailable}
> >
<Trans>Make Primary</Trans> <Trans>Make Primary</Trans>
</Button> </Button>
<Button onClick={() => runServerAction('put')}> <Button
onClick={() => runServerAction('put')}
disabled={emailAvailable}
>
<Trans>Re-send Verification</Trans> <Trans>Re-send Verification</Trans>
</Button> </Button>
<Button onClick={() => runServerAction('delete')}> <Button
onClick={() => runServerAction('delete')}
disabled={emailAvailable}
>
<Trans>Remove</Trans> <Trans>Remove</Trans>
</Button> </Button>
</Group> </Group>