fix Cancel

This commit is contained in:
proddy
2023-06-24 16:51:04 +02:00
parent 89f14f1dba
commit d6c5c87412
2 changed files with 19 additions and 5 deletions

View File

@@ -34,7 +34,8 @@ const SettingsEntities: FC = () => {
send: fetchEntities, send: fetchEntities,
error error
} = useRequest(EMSESP.readEntities, { } = useRequest(EMSESP.readEntities, {
initialData: [] initialData: [],
force: true
}); });
const { send: writeEntities } = useRequest((data) => EMSESP.writeEntities(data), { immediate: false }); const { send: writeEntities } = useRequest((data) => EMSESP.writeEntities(data), { immediate: false });
@@ -146,6 +147,12 @@ const SettingsEntities: FC = () => {
setDialogOpen(false); setDialogOpen(false);
}; };
const onDialogCancel = async () => {
await fetchEntities().then(() => {
setNumChanges(0);
});
};
const onDialogSave = (updatedItem: EntityItem) => { const onDialogSave = (updatedItem: EntityItem) => {
setDialogOpen(false); setDialogOpen(false);
@@ -246,7 +253,7 @@ const SettingsEntities: FC = () => {
<Box flexGrow={1}> <Box flexGrow={1}>
{numChanges > 0 && ( {numChanges > 0 && (
<ButtonRow> <ButtonRow>
<Button startIcon={<CancelIcon />} variant="outlined" onClick={fetchEntities} color="secondary"> <Button startIcon={<CancelIcon />} variant="outlined" onClick={onDialogCancel} color="secondary">
{LL.CANCEL()} {LL.CANCEL()}
</Button> </Button>
<Button <Button

View File

@@ -36,7 +36,8 @@ const SettingsScheduler: FC = () => {
send: fetchSchedule, send: fetchSchedule,
error error
} = useRequest(EMSESP.readSchedule, { } = useRequest(EMSESP.readSchedule, {
initialData: [] initialData: [],
force: true
}); });
const { send: writeSchedule } = useRequest((data) => EMSESP.writeSchedule(data), { immediate: false }); const { send: writeSchedule } = useRequest((data) => EMSESP.writeSchedule(data), { immediate: false });
@@ -144,6 +145,12 @@ const SettingsScheduler: FC = () => {
setDialogOpen(false); setDialogOpen(false);
}; };
const onDialogCancel = async () => {
await fetchSchedule().then(() => {
setNumChanges(0);
});
};
const onDialogSave = (updatedItem: ScheduleItem) => { const onDialogSave = (updatedItem: ScheduleItem) => {
setDialogOpen(false); setDialogOpen(false);
@@ -252,7 +259,7 @@ const SettingsScheduler: FC = () => {
onClose={onDialogClose} onClose={onDialogClose}
onSave={onDialogSave} onSave={onDialogSave}
selectedItem={selectedScheduleItem} selectedItem={selectedScheduleItem}
validator={schedulerItemValidation()} validator={schedulerItemValidation(schedule, selectedScheduleItem)}
dow={dow} dow={dow}
/> />
)} )}
@@ -261,7 +268,7 @@ const SettingsScheduler: FC = () => {
<Box flexGrow={1}> <Box flexGrow={1}>
{numChanges !== 0 && ( {numChanges !== 0 && (
<ButtonRow> <ButtonRow>
<Button startIcon={<CancelIcon />} variant="outlined" onClick={fetchSchedule} color="secondary"> <Button startIcon={<CancelIcon />} variant="outlined" onClick={onDialogCancel} color="secondary">
{LL.CANCEL()} {LL.CANCEL()}
</Button> </Button>
<Button <Button