diff --git a/resources/scripts/components/admin/roles/RoleEditContainer.tsx b/resources/scripts/components/admin/roles/RoleEditContainer.tsx index 3cb1ea24..2616b6ec 100644 --- a/resources/scripts/components/admin/roles/RoleEditContainer.tsx +++ b/resources/scripts/components/admin/roles/RoleEditContainer.tsx @@ -1,13 +1,21 @@ -import React, { useEffect, useState } from 'react'; -import tw from 'twin.macro'; -import { useRouteMatch } from 'react-router-dom'; import { action, Action, Actions, createContextStore, useStoreActions } from 'easy-peasy'; +import React, { useEffect, useState } from 'react'; +// import { useHistory } from 'react-router'; +import { useRouteMatch } from 'react-router-dom'; +import tw from 'twin.macro'; +import { object, string } from 'yup'; import { Role } from '@/api/admin/roles/getRoles'; import getRole from '@/api/admin/roles/getRole'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import Spinner from '@/components/elements/Spinner'; import FlashMessageRender from '@/components/FlashMessageRender'; import { ApplicationStore } from '@/state'; +import { Form, Formik, FormikHelpers } from 'formik'; +import updateRole from '@/api/admin/roles/updateRole'; +import AdminBox from '@/components/admin/AdminBox'; +import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; +import Field from '@/components/elements/Field'; +import Button from '@/components/elements/Button'; interface ctx { role: Role | undefined; @@ -22,6 +30,97 @@ export const Context = createContextStore({ }), }); +interface Values { + name: string; + description: string; +} + +const EditInformationContainer = () => { + // const history = useHistory(); + + const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); + + const role = Context.useStoreState(state => state.role); + const setRole = Context.useStoreActions(actions => actions.setRole); + + if (role === undefined) { + return ( + <> + ); + } + + const submit = ({ name, description }: Values, { setSubmitting }: FormikHelpers) => { + clearFlashes('role'); + + updateRole(role.id, name, description) + .then(() => setRole({ ...role, name, description })) + .catch(error => { + console.error(error); + clearAndAddHttpError({ key: 'role', error }); + }) + .then(() => setSubmitting(false)); + }; + + return ( + + { + ({ isSubmitting, isValid }) => ( + + + + +
+
+ +
+ +
+ +
+ +
+ {/*
*/} + {/* history.push('/admin/roles')} */} + {/* /> */} + {/*
*/} + +
+ +
+
+
+
+
+ ) + } +
+ ); +}; + const RoleEditContainer = () => { const match = useRouteMatch<{ id?: string }>(); @@ -72,6 +171,8 @@ const RoleEditContainer = () => { + + ); };