diff options
Diffstat (limited to 'modern')
-rw-r--r-- | modern/src/DevicePage.js | 14 | ||||
-rw-r--r-- | modern/src/EditItemView.js | 17 | ||||
-rw-r--r-- | modern/src/GeofencePage.js | 9 | ||||
-rw-r--r-- | modern/src/UserPage.js | 14 | ||||
-rw-r--r-- | modern/src/settings/CalendarPage.js | 9 | ||||
-rw-r--r-- | modern/src/settings/CommandPage.js | 4 | ||||
-rw-r--r-- | modern/src/settings/ComputedAttributePage.js | 9 | ||||
-rw-r--r-- | modern/src/settings/DriverPage.js | 9 | ||||
-rw-r--r-- | modern/src/settings/GroupPage.js | 9 | ||||
-rw-r--r-- | modern/src/settings/MaintenancePage.js | 9 | ||||
-rw-r--r-- | modern/src/settings/NotificationPage.js | 14 |
11 files changed, 68 insertions, 49 deletions
diff --git a/modern/src/DevicePage.js b/modern/src/DevicePage.js index def48d9c..e4b853e7 100644 --- a/modern/src/DevicePage.js +++ b/modern/src/DevicePage.js @@ -28,10 +28,11 @@ const DevicePage = () => { const [item, setItem] = useState(); + const validate = () => item && item.name && item.uniqueId; + return ( - <EditItemView endpoint="devices" item={item} setItem={setItem}> - {item - && ( + <EditItemView endpoint="devices" item={item} setItem={setItem} validate={validate}> + {item && ( <> <Accordion defaultExpanded> <AccordionSummary expandIcon={<ExpandMoreIcon />}> @@ -124,8 +125,7 @@ const DevicePage = () => { /> </AccordionDetails> </Accordion> - {item.id - && ( + {item.id && ( <Accordion> <AccordionSummary expandIcon={<ExpandMoreIcon />}> <Typography variant="subtitle1"> @@ -187,9 +187,9 @@ const DevicePage = () => { /> </AccordionDetails> </Accordion> - )} + )} </> - )} + )} </EditItemView> ); }; diff --git a/modern/src/EditItemView.js b/modern/src/EditItemView.js index e1aea2a9..5ffdd9b5 100644 --- a/modern/src/EditItemView.js +++ b/modern/src/EditItemView.js @@ -23,7 +23,7 @@ const useStyles = makeStyles((theme) => ({ })); const EditItemView = ({ - children, endpoint, item, setItem, + children, endpoint, item, setItem, validate, }) => { const history = useHistory(); const classes = useStyles(); @@ -65,10 +65,21 @@ const EditItemView = ({ {children} <FormControl fullWidth margin="normal"> <div className={classes.buttons}> - <Button type="button" color="primary" variant="outlined" onClick={() => history.goBack()}> + <Button + type="button" + color="primary" + variant="outlined" + onClick={() => history.goBack()} + > {t('sharedCancel')} </Button> - <Button type="button" color="primary" variant="contained" onClick={handleSave}> + <Button + type="button" + color="primary" + variant="contained" + onClick={handleSave} + disabled={!validate()} + > {t('sharedSave')} </Button> </div> diff --git a/modern/src/GeofencePage.js b/modern/src/GeofencePage.js index d421a8e1..89762b60 100644 --- a/modern/src/GeofencePage.js +++ b/modern/src/GeofencePage.js @@ -24,10 +24,11 @@ const GeofencePage = () => { const [item, setItem] = useState(); + const validate = () => item && item.name; + return ( - <EditItemView endpoint="geofences" item={item} setItem={setItem}> - {item - && ( + <EditItemView endpoint="geofences" item={item} setItem={setItem} validate={validate}> + {item && ( <> <Accordion defaultExpanded> <AccordionSummary expandIcon={<ExpandMoreIcon />}> @@ -60,7 +61,7 @@ const GeofencePage = () => { </AccordionDetails> </Accordion> </> - )} + )} </EditItemView> ); }; diff --git a/modern/src/UserPage.js b/modern/src/UserPage.js index 895dac43..ce1e082f 100644 --- a/modern/src/UserPage.js +++ b/modern/src/UserPage.js @@ -25,10 +25,11 @@ const UserPage = () => { const [item, setItem] = useState(); + const validate = () => item && item.name && item.email && (item.id || item.password); + return ( - <EditItemView endpoint="users" item={item} setItem={setItem}> - {item - && ( + <EditItemView endpoint="users" item={item} setItem={setItem} validate={validate}> + {item && ( <> <Accordion defaultExpanded> <AccordionSummary expandIcon={<ExpandMoreIcon />}> @@ -97,8 +98,7 @@ const UserPage = () => { /> </AccordionDetails> </Accordion> - {item.id - && ( + {item.id && ( <Accordion> <AccordionSummary expandIcon={<ExpandMoreIcon />}> <Typography variant="subtitle1"> @@ -128,9 +128,9 @@ const UserPage = () => { /> </AccordionDetails> </Accordion> - )} + )} </> - )} + )} </EditItemView> ); }; diff --git a/modern/src/settings/CalendarPage.js b/modern/src/settings/CalendarPage.js index 60d4ef76..0d35d2f3 100644 --- a/modern/src/settings/CalendarPage.js +++ b/modern/src/settings/CalendarPage.js @@ -34,10 +34,11 @@ const CalendarPage = () => { } }; + const validate = () => item && item.name && item.data; + return ( - <EditItemView endpoint="calendars" item={item} setItem={setItem}> - {item - && ( + <EditItemView endpoint="calendars" item={item} setItem={setItem} validate={validate}> + {item && ( <> <Accordion defaultExpanded> <AccordionSummary expandIcon={<ExpandMoreIcon />}> @@ -74,7 +75,7 @@ const CalendarPage = () => { </AccordionDetails> </Accordion> </> - )} + )} </EditItemView> ); }; diff --git a/modern/src/settings/CommandPage.js b/modern/src/settings/CommandPage.js index 8a7f5b94..0b0f54b6 100644 --- a/modern/src/settings/CommandPage.js +++ b/modern/src/settings/CommandPage.js @@ -30,8 +30,10 @@ const CommandPage = () => { } }, [availableAttributes, item]); + const validate = () => item && item.type; + return ( - <EditItemView endpoint="commands" item={item} setItem={setItem}> + <EditItemView endpoint="commands" item={item} setItem={setItem} validate={validate}> {item && ( <Accordion defaultExpanded> <AccordionSummary expandIcon={<ExpandMoreIcon />}> diff --git a/modern/src/settings/ComputedAttributePage.js b/modern/src/settings/ComputedAttributePage.js index 99bbfadb..2aa40ef0 100644 --- a/modern/src/settings/ComputedAttributePage.js +++ b/modern/src/settings/ComputedAttributePage.js @@ -39,10 +39,11 @@ const ComputedAttributePage = () => { } }; + const validate = () => item && item.description && item.expression; + return ( - <EditItemView endpoint="attributes/computed" item={item} setItem={setItem}> - {item - && ( + <EditItemView endpoint="attributes/computed" item={item} setItem={setItem} validate={validate}> + {item && ( <Accordion defaultExpanded> <AccordionSummary expandIcon={<ExpandMoreIcon />}> <Typography variant="subtitle1"> @@ -95,7 +96,7 @@ const ComputedAttributePage = () => { </FormControl> </AccordionDetails> </Accordion> - )} + )} </EditItemView> ); }; diff --git a/modern/src/settings/DriverPage.js b/modern/src/settings/DriverPage.js index a185405e..ff703916 100644 --- a/modern/src/settings/DriverPage.js +++ b/modern/src/settings/DriverPage.js @@ -20,10 +20,11 @@ const DriverPage = () => { const [item, setItem] = useState(); + const validate = () => item && item.name && item.uniqueId; + return ( - <EditItemView endpoint="drivers" item={item} setItem={setItem}> - {item - && ( + <EditItemView endpoint="drivers" item={item} setItem={setItem} validate={validate}> + {item && ( <> <Accordion defaultExpanded> <AccordionSummary expandIcon={<ExpandMoreIcon />}> @@ -63,7 +64,7 @@ const DriverPage = () => { </AccordionDetails> </Accordion> </> - )} + )} </EditItemView> ); }; diff --git a/modern/src/settings/GroupPage.js b/modern/src/settings/GroupPage.js index be14e96e..3750fc0e 100644 --- a/modern/src/settings/GroupPage.js +++ b/modern/src/settings/GroupPage.js @@ -25,10 +25,11 @@ const GroupPage = () => { const [item, setItem] = useState(); + const validate = () => item && item.name; + return ( - <EditItemView endpoint="groups" item={item} setItem={setItem}> - {item - && ( + <EditItemView endpoint="groups" item={item} setItem={setItem} validate={validate}> + {item && ( <> <Accordion defaultExpanded> <AccordionSummary expandIcon={<ExpandMoreIcon />}> @@ -78,7 +79,7 @@ const GroupPage = () => { </AccordionDetails> </Accordion> </> - )} + )} </EditItemView> ); }; diff --git a/modern/src/settings/MaintenancePage.js b/modern/src/settings/MaintenancePage.js index c157ff48..a612abb7 100644 --- a/modern/src/settings/MaintenancePage.js +++ b/modern/src/settings/MaintenancePage.js @@ -94,10 +94,11 @@ const MaintenancePage = () => { return value; }; + const validate = () => item && item.name && item.type && item.start && item.period; + return ( - <EditItemView endpoint="maintenance" item={item} setItem={setItem}> - {item - && ( + <EditItemView endpoint="maintenance" item={item} setItem={setItem} validate={validate}> + {item && ( <> <Accordion defaultExpanded> <AccordionSummary expandIcon={<ExpandMoreIcon />}> @@ -163,7 +164,7 @@ const MaintenancePage = () => { </AccordionDetails> </Accordion> </> - )} + )} </EditItemView> ); }; diff --git a/modern/src/settings/NotificationPage.js b/modern/src/settings/NotificationPage.js index 67c4ee05..0352683a 100644 --- a/modern/src/settings/NotificationPage.js +++ b/modern/src/settings/NotificationPage.js @@ -26,10 +26,11 @@ const NotificationPage = () => { name: t(it), })); + const validate = () => item && item.type && item.notificators; + return ( - <EditItemView endpoint="notifications" item={item} setItem={setItem}> - {item - && ( + <EditItemView endpoint="notifications" item={item} setItem={setItem} validate={validate}> + {item && ( <> <Accordion defaultExpanded> <AccordionSummary expandIcon={<ExpandMoreIcon />}> @@ -60,8 +61,7 @@ const NotificationPage = () => { label={t('notificationNotificators')} variant="filled" /> - {(!item.type || item.type === 'alarm') - && ( + {(!item.type || item.type === 'alarm') && ( <SelectField multiple margin="normal" @@ -72,7 +72,7 @@ const NotificationPage = () => { label={t('sharedAlarms')} variant="filled" /> - )} + )} <FormControlLabel control={( <Checkbox @@ -85,7 +85,7 @@ const NotificationPage = () => { </AccordionDetails> </Accordion> </> - )} + )} </EditItemView> ); }; |