Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

228 save disabled popup #273

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/packages/common/src/intl/locales/en/system.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"label.new-query": "New Query",
"label.new-user": "New User",
"label.new-notification": "New Notification",
"label.notification-is-disabled": "Notification is disabled",
"label.notification-title": "Notification Title",
"label.notification-type-EMAIL": "Email",
"label.notification-type-TELEGRAM": "Telegram",
Expand Down Expand Up @@ -81,6 +82,8 @@
"messages.recipients-added_one": "{{count}} recipient added to list",
"messages.query-result-count_other": "Result: {{count}} rows",
"messages.query-result-count_one": "Result: {{count}} row",
"messages.saving-disabled-valid-notification": "Did you mean to enable this notification before you saved it?",
"messages.saving-enabled-invalid-notification": "To save an enabled notification, it must have valid configuration",
"messages.cold-chain-no-data-information": "Alert will be triggered if no temperature data is received by the server within the specified timeframe",
"messages.cold-chain-temperature-information": "Default Temperature thresholds are 2Β°C and 8Β°C",
"not-logged-in": "Not logged in",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
RouteBuilder,
BaseButton,
ListIcon,
Tooltip,
} from '@notify-frontend/common';

import { BaseNotificationConfig } from '../../types';
Expand Down Expand Up @@ -160,6 +161,17 @@ export const BaseNotificationEditPage = <T extends BaseNotificationConfig>({
}
});

const saveConfig = () => {
onSave(draft);
setIsSaved(true);
};

const confirmBeforeSaving = useConfirmationModal({
title: t('label.notification-is-disabled'),
message: t('messages.saving-disabled-valid-notification'),
onConfirm: saveConfig,
});

return (
<>
{isLoading ? (
Expand Down Expand Up @@ -286,8 +298,7 @@ export const BaseNotificationEditPage = <T extends BaseNotificationConfig>({
onClick={() => {
// Note, this doesn't update state, but that's good we don't want to save the nextDueDatetime again if the save button is used next.
draft.nextDueDatetime = new Date().toISOString();
onSave(draft);
setIsSaved(true);
saveConfig();
}}
startIcon={<RunIcon />}
sx={{ fontSize: '12px' }}
Expand All @@ -296,18 +307,36 @@ export const BaseNotificationEditPage = <T extends BaseNotificationConfig>({
</LoadingButton>
)}

<LoadingButton
disabled={isSaved || isInvalid || !allParamsSet}
isLoading={isLoading}
onClick={() => {
onSave(draft);
setIsSaved(true);
}}
startIcon={<SaveIcon />}
sx={{ fontSize: '12px' }}
<Tooltip
title={
isEnabled(draft.status) && isInvalid
? t('messages.saving-enabled-invalid-notification')
: ''
}
>
{t('button.save')}
</LoadingButton>
<span>
<LoadingButton
disabled={
isSaved ||
(isEnabled(draft.status) && isInvalid) ||
!allParamsSet
}
isLoading={isLoading}
onClick={() => {
// prompt user if saving a valid config with disabled status - they may have forgotten to enable
if (!isInvalid && !isEnabled(draft.status)) {
confirmBeforeSaving();
} else {
saveConfig();
}
}}
startIcon={<SaveIcon />}
sx={{ fontSize: '12px' }}
>
{t('button.save')}
</LoadingButton>
</span>
</Tooltip>
</Box>
</Box>
}
Expand Down
Loading