diff --git a/resources/scripts/components/admin/locations/LocationEditContainer.tsx b/resources/scripts/components/admin/locations/LocationEditContainer.tsx index 7f69b5dc..465d9009 100644 --- a/resources/scripts/components/admin/locations/LocationEditContainer.tsx +++ b/resources/scripts/components/admin/locations/LocationEditContainer.tsx @@ -8,6 +8,13 @@ import AdminContentBlock from '@/components/admin/AdminContentBlock'; import Spinner from '@/components/elements/Spinner'; import FlashMessageRender from '@/components/FlashMessageRender'; import { ApplicationStore } from '@/state'; +import { object, string } from 'yup'; +import AdminBox from '@/components/admin/AdminBox'; +import Button from '@/components/elements/Button'; +import Field from '@/components/elements/Field'; +import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; +import { Form, Formik, FormikHelpers } from 'formik'; +import updateLocation from '@/api/admin/locations/updateLocation'; interface ctx { location: Location | undefined; @@ -22,6 +29,85 @@ export const Context = createContextStore({ }), }); +interface Values { + short: string; + long: string; +} + +const EditInformationContainer = () => { + const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); + const location = Context.useStoreState(state => state.location); + const setLocation = Context.useStoreActions(actions => actions.setLocation); + + if (location === undefined) { + return ( + <> + ); + } + + const submit = ({ short, long }: Values, { setSubmitting }: FormikHelpers) => { + clearFlashes('location'); + + updateLocation(location.id, short, long) + .then(() => setLocation({ ...location, short, long })) + .catch(error => { + console.error(error); + clearAndAddHttpError({ key: 'location', error }); + }) + .then(() => setSubmitting(false)); + }; + + return ( + + { + ({ isSubmitting, isValid }) => ( + + + + +
+
+ +
+ +
+ +
+ +
+ +
+
+
+
+ ) + } +
+ ); +}; + const LocationEditContainer = () => { const match = useRouteMatch<{ id?: string }>(); @@ -60,11 +146,20 @@ const LocationEditContainer = () => {

{location.short}

-

{location.long}

+ { + (location.long || '').length < 1 ? +

+ No long name +

+ : +

{location.long}

+ }
+ + ); };