diff --git a/src/modules/apps/AppSingle.tsx b/src/modules/apps/AppSingle.tsx index 2d074a2..d3cb8e5 100644 --- a/src/modules/apps/AppSingle.tsx +++ b/src/modules/apps/AppSingle.tsx @@ -58,7 +58,7 @@ export const AppSingle: React.FC = () => { const tabs = [ { name: 'General', - component: , + component: , }, { name: 'Advanced Configuration', component: }, ]; diff --git a/src/modules/apps/components/GeneralTab/GeneralTab.tsx b/src/modules/apps/components/GeneralTab/GeneralTab.tsx index c930b5d..5211a7f 100644 --- a/src/modules/apps/components/GeneralTab/GeneralTab.tsx +++ b/src/modules/apps/components/GeneralTab/GeneralTab.tsx @@ -1,45 +1,61 @@ -import React from 'react'; -import { Switch } from '@headlessui/react'; +import _ from 'lodash'; +import React, { useEffect, useRef } from 'react'; +import { SubmitHandler, useForm } from 'react-hook-form'; +import { Switch } from 'src/components/Form'; +import { App, useApps } from 'src/services/apps'; -function classNames(...classes: any) { - return classes.filter(Boolean).join(' '); -} +export const GeneralTab = () => { + const { app, editApp } = useApps(); + const { control, reset, handleSubmit } = useForm({ + defaultValues: { automaticUpdates: false }, + }); -interface GeneralTabProps { - automaticUpdates: boolean; - onChange: () => void; -} + useEffect(() => { + if (!_.isEmpty(app)) { + reset(app); + } + + return () => { + reset({ automaticUpdates: false }); + }; + }, [app, reset]); + + const onSubmit: SubmitHandler = (data) => { + try { + editApp(data); + } catch (e: any) { + // continue + } + }; -export const GeneralTab = ({ automaticUpdates, onChange }: GeneralTabProps) => { return ( -
-
-
-

Automatic updates

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et nibh sit amet mauris faucibus molestie - gravida at orci. -

+ <> +
+
+
+
+

Automatic updates

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et nibh sit amet mauris faucibus molestie + gravida at orci. +

+
+
+ +
+
-
- - +
+
+ +
-
-
+ + ); }; diff --git a/src/services/apps/hooks/use-apps.ts b/src/services/apps/hooks/use-apps.ts index 919bebe..521df87 100644 --- a/src/services/apps/hooks/use-apps.ts +++ b/src/services/apps/hooks/use-apps.ts @@ -1,5 +1,5 @@ import { useDispatch, useSelector } from 'react-redux'; -import { fetchApps, fetchAppBySlug, updateAppBySlug, installAppBySlug, clearCurrentApp, deleteApp } from '../redux'; +import { fetchApps, fetchAppBySlug, updateApp, installAppBySlug, clearCurrentApp, deleteApp } from '../redux'; import { getCurrentApp, getAppLoading, getAppsLoading, getApps } from '../redux/selectors'; export function useApps() { @@ -17,8 +17,8 @@ export function useApps() { return dispatch(fetchAppBySlug(slug)); } - function editAppBySlug(data: any) { - return dispatch(updateAppBySlug(data)); + function editApp(data: any) { + return dispatch(updateApp(data)); } function installApp(data: any) { @@ -38,7 +38,7 @@ export function useApps() { app, loadApp, loadApps, - editAppBySlug, + editApp, appLoading, appTableLoading, installApp, diff --git a/src/services/apps/redux/actions.ts b/src/services/apps/redux/actions.ts index 8bd4d48..17b8f2c 100644 --- a/src/services/apps/redux/actions.ts +++ b/src/services/apps/redux/actions.ts @@ -68,7 +68,7 @@ export const fetchAppBySlug = (slug: string) => async (dispatch: Dispatch) dispatch(setAppLoading(false)); }; -export const updateAppBySlug = (app: any) => async (dispatch: Dispatch) => { +export const updateApp = (app: any) => async (dispatch: Dispatch) => { dispatch(setAppLoading(true)); try { @@ -83,6 +83,8 @@ export const updateAppBySlug = (app: any) => async (dispatch: Dispatch) => payload: transformApp(data), }); + showToast('App is updated!', ToastType.Success); + dispatch(fetchApps()); } catch (err) { console.error(err);