import type React from "react"; import { useEffect, useState } from "react"; import { FormField, Switch, TextInputField } from "evergreen-ui"; import { Controller, useForm, useWatch } from "react-hook-form"; import { StoreForwardValidation } from "@app/validation/moduleConfig/storeForward.js"; import { Form } from "@components/form/Form"; import { useDevice } from "@core/stores/deviceStore.js"; import { classValidatorResolver } from "@hookform/resolvers/class-validator"; export const StoreForward = (): JSX.Element => { const { moduleConfig, connection } = useDevice(); const [loading, setLoading] = useState(false); const { register, handleSubmit, formState: { errors, isDirty }, reset, control, } = useForm({ defaultValues: moduleConfig.storeForward, resolver: classValidatorResolver(StoreForwardValidation), }); useEffect(() => { reset(moduleConfig.storeForward); }, [reset, moduleConfig.storeForward]); const onSubmit = handleSubmit(async (data) => { setLoading(true); await connection?.setModuleConfig( { payloadVariant: { oneofKind: "storeForward", storeForward: data, }, }, async (): Promise => { reset({ ...data }); setLoading(false); await Promise.resolve(); } ); }); const moduleEnabled = useWatch({ control, name: "enabled", defaultValue: false, }); return (
( )} /> ( )} /> ); };