import React from 'react'; import { react2angular } from 'react2angular'; import { SubmitHandler, useForm, useWatch } from 'react-hook-form'; import { User } from '../../models/user'; import { IApplication } from '../../models/application'; import { Loader } from '../base/loader'; import { FormInput } from '../form/form-input'; import { useTranslation } from 'react-i18next'; import { Avatar } from './avatar'; import { GenderInput } from './gender-input'; import { ChangePassword } from './change-password'; import Switch from 'react-switch'; import { PasswordInput } from './password-input'; declare const Application: IApplication; interface UserProfileFormProps { action: 'create' | 'update', size?: 'small' | 'large', user: User, className?: string, onError: (message: string) => void, } export const UserProfileForm: React.FC = ({ action, size, user, className, onError }) => { const { t } = useTranslation('shared'); const { handleSubmit, register, control, formState } = useForm({ defaultValues: { ...user } }); const output = useWatch({ control }); const [isOrganization, setIsOrganization] = React.useState(user.invoicing_profile.organization !== null); /** * Callback triggered when the form is submitted: process with the user creation or update. */ const onSubmit: SubmitHandler = (data: User) => { console.log(action, data); }; return (

{t('app.shared.user_profile_form.personal_data')}

{t('app.shared.user_profile_form.account_data')}

{/* TODO: no password change if sso */} {action === 'update' && } {action === 'create' && }

{t('app.shared.user_profile_form.organization_data')}

{isOrganization &&
}
); }; UserProfileForm.defaultProps = { size: 'large' }; const UserProfileFormWrapper: React.FC = (props) => { return ( ); }; Application.Components.component('userProfileForm', react2angular(UserProfileFormWrapper, ['action', 'size', 'user', 'className', 'onError']));