import * as React from 'react'; import { useState } from 'react'; import { IApplication } from '../../models/application'; import { Loader } from '../base/loader'; import { react2angular } from 'react2angular'; import { ErrorBoundary } from '../base/error-boundary'; import { useTranslation } from 'react-i18next'; import { useForm, SubmitHandler } from 'react-hook-form'; import { FormRichText } from '../form/form-rich-text'; import { FormSwitch } from '../form/form-switch'; import { FormInput } from '../form/form-input'; import { FabButton } from '../base/fab-button'; declare const Application: IApplication; interface MachinesSettingsProps { onError: (message: string) => void, onSuccess: (message: string) => void, } /** * Machines settings */ export const MachinesSettings: React.FC = () => { const { t } = useTranslation('admin'); const { register, control, formState, handleSubmit } = useForm(); // regular expression to validate the input fields const urlRegex = /^(https?:\/\/)([^.]+)\.(.{2,30})(\/.*)*\/?$/; const [isActiveAutoCancellation, setIsActiveAutoCancellation] = useState(false); const [isActiveAuthorizationValidity, setIsActiveAuthorizationValidity] = useState(false); const [isActiveTextBlock, setIsActiveTextBlock] = useState(false); const [isActiveValidationRule, setIsActiveValidationRule] = useState(false); const [isActiveCta, setIsActiveCta] = useState(false); /** * Callback triggered when the auto cancellation switch has changed. */ const toggleAutoCancellation = (value: boolean) => { setIsActiveAutoCancellation(value); }; /** * Callback triggered when the authorisation validity switch has changed. */ const toggleAuthorizationValidity = (value: boolean) => { setIsActiveAuthorizationValidity(value); }; /** * Callback triggered when the authorisation validity switch has changed. */ const toggleValidationRule = (value: boolean) => { setIsActiveValidationRule(value); }; /** * Callback triggered when the text block switch has changed. */ const toggleTextBlockSwitch = (value: boolean) => { setIsActiveTextBlock(value); }; /** * Callback triggered when the CTA switch has changed. */ const toggleTextBlockCta = (value: boolean) => { setIsActiveCta(value); }; /** * Callback triggered when the CTA label has changed. */ const handleCtaLabelChange = (event: React.ChangeEvent): void => { console.log('cta label:', event.target.value); }; /** * Callback triggered when the cta url has changed. */ const handleCtaUrlChange = (event: React.ChangeEvent): void => { console.log('cta url:', event.target.value); }; /** * Callback triggered when the form is submitted: save the settings */ const onSubmit: SubmitHandler = (data) => { console.log(data); }; return (

{t('app.admin.machines_settings.title')}

{t('app.admin.machines_settings.save')}

{t('app.admin.machines_settings.generic_text_block')}

{t('app.admin.machines_settings.generic_text_block_info')}

{isActiveTextBlock && <> {isActiveCta && <> } }
); }; const MachinesSettingsWrapper: React.FC = (props) => { return ( ); }; Application.Components.component('machinesSettings', react2angular(MachinesSettingsWrapper, ['onError', 'onSuccess']));