1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-10 00:46:15 +01:00
fab-manager/app/frontend/src/javascript/components/user/user-profile-form.tsx

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-04-25 17:23:50 +02:00
import React from 'react';
import { react2angular } from 'react2angular';
import { SubmitHandler, useForm } 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';
declare const Application: IApplication;
interface UserProfileFormProps {
action: 'create' | 'update',
user: User;
className?: string;
}
export const UserProfileForm: React.FC<UserProfileFormProps> = ({ action, user, className }) => {
const { handleSubmit, register } = useForm<User>({ defaultValues: { ...user } });
/**
* Callback triggered when the form is submitted: process with the user creation or update.
*/
const onSubmit: SubmitHandler<User> = (data: User) => {
console.log(action, data);
};
return (
<form className={`user-profile-form ${className}`} onSubmit={handleSubmit(onSubmit)}>
<FormInput id="email" register={register} rules={{ required: true }} label="email" />
</form>
);
};
const UserProfileFormWrapper: React.FC<UserProfileFormProps> = (props) => {
return (
<Loader>
<UserProfileForm {...props} />
</Loader>
);
};
Application.Components.component('userProfileForm', react2angular(UserProfileFormWrapper, ['action', 'user', 'className']));