Starting UI change to warn if linked TZ is selected

This commit is contained in:
John Westcott IV
2022-05-31 17:09:41 -04:00
parent c836fafb61
commit b05ebe9623

View File

@@ -89,7 +89,7 @@ const generateRunOnTheDay = (days = []) => {
return null; return null;
}; };
function ScheduleFormFields({ hasDaysToKeepField, zoneOptions }) { function ScheduleFormFields({ hasDaysToKeepField, zoneOptions, zoneLinks }) {
const [timezone, timezoneMeta] = useField({ const [timezone, timezoneMeta] = useField({
name: 'timezone', name: 'timezone',
validate: required(t`Select a value for this field`), validate: required(t`Select a value for this field`),
@@ -100,6 +100,15 @@ function ScheduleFormFields({ hasDaysToKeepField, zoneOptions }) {
}); });
const [{ name: dateFieldName }] = useField('startDate'); const [{ name: dateFieldName }] = useField('startDate');
const [{ name: timeFieldName }] = useField('startTime'); const [{ name: timeFieldName }] = useField('startTime');
const warnLinkedTZ = (event, selected_value) => {
console.log(selected_value)
console.log(event)
if(selected_value in zoneLinks) {
console.log("Warning: "+ selected_value +" is a link to "+ zoneLinks[selected_value] +" and will be saved as that.")
}
timezone.onChange();
};
return ( return (
<> <>
<FormField <FormField
@@ -135,6 +144,7 @@ function ScheduleFormFields({ hasDaysToKeepField, zoneOptions }) {
id="schedule-timezone" id="schedule-timezone"
data={zoneOptions} data={zoneOptions}
{...timezone} {...timezone}
onChange={warnLinkedTZ}
/> />
</FormGroup> </FormGroup>
<FormGroup <FormGroup
@@ -212,7 +222,7 @@ function ScheduleForm({
request: loadScheduleData, request: loadScheduleData,
error: contentError, error: contentError,
isLoading: contentLoading, isLoading: contentLoading,
result: { zoneOptions, credentials }, result: { zoneOptions, zoneLinks, credentials },
} = useRequest( } = useRequest(
useCallback(async () => { useCallback(async () => {
const { data } = await SchedulesAPI.readZoneInfo(); const { data } = await SchedulesAPI.readZoneInfo();
@@ -225,19 +235,21 @@ function ScheduleForm({
creds = results; creds = results;
} }
const zones = data.map((zone) => ({ const zones = data.zones.map((zone) => ({
value: zone.name, value: zone,
key: zone.name, key: zone,
label: zone.name, label: zone,
})); }));
return { return {
zoneOptions: zones, zoneOptions: zones,
zoneLinks: data.zones.links,
credentials: creds || [], credentials: creds || [],
}; };
}, [schedule]), }, [schedule]),
{ {
zonesOptions: [], zonesOptions: [],
zoneLinks: {},
credentials: [], credentials: [],
isLoading: true, isLoading: true,
} }