diff --git a/.prettierignore b/.prettierignore index f71737da..15976c07 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ node_modules package.json package-lock.json +frontend \ No newline at end of file diff --git a/controllers/app-config.js b/controllers/app-config.js index 79badb45..13369add 100644 --- a/controllers/app-config.js +++ b/controllers/app-config.js @@ -11,6 +11,7 @@ const mongoUtils = require('../nodejs/mongo-utils'); const scheduler = require('../nodejs/scheduler'); const { agenda } = require('../nodejs/agenda'); const parksList = require('../config/parks'); +const parks = require('../nodejs/parks'); const statesList = require('../config/states'); const countriesList = require('../config/countries'); const appModules = require('../nodejs/app-modules'); @@ -73,13 +74,18 @@ exports.getConfig = async (req, res) => { * POST /app-config * Save application config */ -exports.saveConfig = (req, res, next) => { +exports.saveConfig = async (req, res, next) => { const data = req.body; if (!data) { return next('No config data to save'); } + if (data.appName === 'parks') { + // eslint-disable-next-line no-underscore-dangle + await parks.save(req.user._id); + } + if (data.parks && data.parks.visited) { data.parks.visited = data.parks.visited.map((x) => x.value); } diff --git a/frontend/src/pages/app-settings/app-settings.tsx b/frontend/src/pages/app-settings/app-settings.tsx index 1a469d92..3d40c1de 100644 --- a/frontend/src/pages/app-settings/app-settings.tsx +++ b/frontend/src/pages/app-settings/app-settings.tsx @@ -72,7 +72,10 @@ const AppSettings: React.FC = () => { setSaveSuccess(false); try { - const { data: response }: ServerResponse = await Request.post({ url: '/app-config/config', body }); + const { data: response }: ServerResponse = await Request.post({ + url: '/app-config/config', + body: { ...body, appName }, + }); setData(response.data); setSaveSuccess(true); } catch (e: any) { diff --git a/frontend/src/pages/app-settings/parks-settings.tsx b/frontend/src/pages/app-settings/parks-settings.tsx index f1b496a5..2a155b4f 100644 --- a/frontend/src/pages/app-settings/parks-settings.tsx +++ b/frontend/src/pages/app-settings/parks-settings.tsx @@ -1,16 +1,21 @@ import React, { useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; +import { makeStyles } from '@material-ui/core/styles'; -import { Button, Form, MultiSelect2 } from '@schulzetenberg/component-library'; +import { Button, Form, MultiSelect2, SwitchForm2 } from '@schulzetenberg/component-library'; + +const useStyles = makeStyles(() => ({ + textCenter: { textAlign: 'center' }, +})); type FormData = { visited: { value: string; label: string }[]; options: { value: string; label: string }[]; - schedule: string; cloudinaryUpload: boolean; }; const ParksSettings: React.FC<{ data: FormData; isLoading: boolean; submit: any }> = ({ data, isLoading, submit }) => { + const classes = useStyles(); const [options, setOptions] = useState<{ value: string; label: string }[]>([]); const { @@ -26,14 +31,17 @@ const ParksSettings: React.FC<{ data: FormData; isLoading: boolean; submit: any if (data) { setOptions(data.options); - const { visited } = data; - reset({ visited }); + const { visited, cloudinaryUpload } = data; + reset({ visited, cloudinaryUpload }); } }, [data, reset]); return (