diff --git a/new-lamassu-admin/src/components/PromptWhenDirty.js b/new-lamassu-admin/src/components/PromptWhenDirty.js
new file mode 100644
index 00000000..075bd15c
--- /dev/null
+++ b/new-lamassu-admin/src/components/PromptWhenDirty.js
@@ -0,0 +1,16 @@
+import { useFormikContext } from 'formik'
+import React from 'react'
+import { Prompt } from 'react-router-dom'
+
+const PROMPT_DEFAULT_MESSAGE =
+ 'You have unsaved changes on this page. Are you sure you want to leave?'
+
+const PromptWhenDirty = ({ message = PROMPT_DEFAULT_MESSAGE }) => {
+ const formik = useFormikContext()
+
+ return (
+
+ )
+}
+
+export default PromptWhenDirty
diff --git a/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js b/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js
index 66045266..ca739b89 100644
--- a/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js
+++ b/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js
@@ -1,117 +1,110 @@
import { makeStyles } from '@material-ui/core/styles'
import classnames from 'classnames'
+import { useFormikContext, Form, Formik, Field as FormikField } from 'formik'
+import _ from 'lodash'
import React, { useState, memo } from 'react'
+import * as Yup from 'yup'
+import PromptWhenDirty from 'src/components/PromptWhenDirty'
import { Link } from 'src/components/buttons'
-import { RadioGroup } from 'src/components/inputs'
+import { RadioGroup } from 'src/components/inputs/formik'
import { Table, TableBody, TableRow, TableCell } from 'src/components/table'
-import BooleanCell from 'src/components/tables/BooleanCell'
import { H4 } from 'src/components/typography'
import { ReactComponent as EditIconDisabled } from 'src/styling/icons/action/edit/disabled.svg'
import { ReactComponent as EditIcon } from 'src/styling/icons/action/edit/enabled.svg'
+import { ReactComponent as FalseIcon } from 'src/styling/icons/table/false.svg'
+import { ReactComponent as TrueIcon } from 'src/styling/icons/table/true.svg'
import { booleanPropertiesTableStyles } from './BooleanPropertiesTable.styles'
const useStyles = makeStyles(booleanPropertiesTableStyles)
+const BooleanCell = ({ name }) => {
+ const { values } = useFormikContext()
+ return values[name] === 'true' ? :
+}
+
const BooleanPropertiesTable = memo(
({ title, disabled, data, elements, save }) => {
+ const initialValues = _.fromPairs(elements.map(it => [it.name, '']))
+ const schemaValidation = _.fromPairs(
+ elements.map(it => [it.name, Yup.boolean().required()])
+ )
+
const [editing, setEditing] = useState(false)
- const [radioGroupValues, setRadioGroupValues] = useState(elements)
const classes = useStyles()
- const innerSave = () => {
- radioGroupValues.forEach(element => {
- data[element.name] = element.value
- })
-
- save(data)
+ const innerSave = async value => {
+ save(value)
setEditing(false)
}
- const innerCancel = () => {
- setRadioGroupValues(elements)
- setEditing(false)
- }
-
- const handleRadioButtons = (elementName, newValue) => {
- setRadioGroupValues(
- radioGroupValues.map(element =>
- element.name === elementName
- ? { ...element, value: newValue }
- : element
- )
- )
- }
+ const innerCancel = () => setEditing(false)
const radioButtonOptions = [
- { display: 'Yes', code: true },
- { display: 'No', code: false }
+ { display: 'Yes', code: 'true' },
+ { display: 'No', code: 'false' }
]
- if (!elements || radioGroupValues?.length === 0) return null
-
return (
-
-
{title}
- {editing ? (
-
-
- Cancel
-
-
- Save
-
+
+
-
-
- {radioGroupValues &&
- radioGroupValues.map((element, idx) => (
-
-
- {element.display}
-
-
- {editing && (
-
- handleRadioButtons(
- element.name,
- event.target.value === 'true'
- )
- }
- className={classnames(
- classes.radioButtons,
- classes.rightTableCell
- )}
- />
- )}
- {!editing && (
-
- )}
-
-
- ))}
-
-
+
+
+
+ {elements.map((it, idx) => (
+
+
+ {it.display}
+
+
+ {editing && (
+
+ )}
+ {!editing && }
+
+
+ ))}
+
+
+
+
)
}
diff --git a/new-lamassu-admin/src/components/editableTable/Table.js b/new-lamassu-admin/src/components/editableTable/Table.js
index 094ceca0..4a769ca5 100644
--- a/new-lamassu-admin/src/components/editableTable/Table.js
+++ b/new-lamassu-admin/src/components/editableTable/Table.js
@@ -4,6 +4,7 @@ import * as R from 'ramda'
import React, { useState } from 'react'
import { v4 } from 'uuid'
+import PromptWhenDirty from 'src/components/PromptWhenDirty'
import Link from 'src/components/buttons/Link.js'
import { AddButton } from 'src/components/buttons/index.js'
import { TBody, Table } from 'src/components/fake-table/Table'
@@ -159,6 +160,7 @@ const ETable = ({
validationSchema={validationSchema}
onSubmit={innerSave}>
diff --git a/new-lamassu-admin/src/components/tables/BooleanCell.js b/new-lamassu-admin/src/components/tables/BooleanCell.js
deleted file mode 100644
index 08febd27..00000000
--- a/new-lamassu-admin/src/components/tables/BooleanCell.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import React from 'react'
-
-import { ReactComponent as FalseIcon } from 'src/styling/icons/table/false.svg'
-import { ReactComponent as TrueIcon } from 'src/styling/icons/table/true.svg'
-
-const BooleanCell = ({ value }) => (value ?
:
)
-
-export default BooleanCell
diff --git a/new-lamassu-admin/src/pages/Notifications/components/SingleFieldEditableNumber.js b/new-lamassu-admin/src/pages/Notifications/components/SingleFieldEditableNumber.js
index 52a0e866..355b817f 100644
--- a/new-lamassu-admin/src/pages/Notifications/components/SingleFieldEditableNumber.js
+++ b/new-lamassu-admin/src/pages/Notifications/components/SingleFieldEditableNumber.js
@@ -2,6 +2,8 @@ import { Form, Formik } from 'formik'
import React, { useContext } from 'react'
import * as Yup from 'yup'
+import PromptWhenDirty from 'src/components/PromptWhenDirty'
+
import NotificationsCtx from '../NotificationsContext'
import Header from './EditHeader'
@@ -41,6 +43,7 @@ const SingleFieldEditableNumber = ({
setEditing(name, false)
}}>