1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-19 08:52:25 +01:00

(bug) display date in user form

This commit is contained in:
Sylvain 2022-05-03 16:34:27 +02:00
parent 7ee4c8f4c0
commit 040636da62
2 changed files with 13 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useEffect } from 'react';
import { react2angular } from 'react2angular'; import { react2angular } from 'react2angular';
import { SubmitHandler, useForm, useWatch } from 'react-hook-form'; import { SubmitHandler, useForm, useWatch } from 'react-hook-form';
import { isNil as _isNil } from 'lodash'; import { isNil as _isNil } from 'lodash';
@ -14,6 +14,8 @@ import { FormSwitch } from '../form/form-switch';
import { FormRichText } from '../form/form-rich-text'; import { FormRichText } from '../form/form-rich-text';
import MemberAPI from '../../api/member'; import MemberAPI from '../../api/member';
import { AvatarInput } from './avatar-input'; import { AvatarInput } from './avatar-input';
import moment from 'moment';
import { TDateISODate } from '../../typings/date-iso';
declare const Application: IApplication; declare const Application: IApplication;
@ -36,6 +38,14 @@ export const UserProfileForm: React.FC<UserProfileFormProps> = ({ action, size,
const { handleSubmit, register, control, formState, setValue } = useForm<User>({ defaultValues: { ...user } }); const { handleSubmit, register, control, formState, setValue } = useForm<User>({ defaultValues: { ...user } });
const output = useWatch<User>({ control }); const output = useWatch<User>({ control });
useEffect(() => {
// this is a workaround needed because something in angular.js is transforming the YYY-MM-DD string to a Date Object
setValue(
'statistic_profile_attributes.birthday',
moment(user.statistic_profile_attributes.birthday).format('YYYY-MM-DD') as TDateISODate
);
}, [user]);
const [isOrganization, setIsOrganization] = React.useState<boolean>(!_isNil(user.invoicing_profile_attributes.organization_attributes)); const [isOrganization, setIsOrganization] = React.useState<boolean>(!_isNil(user.invoicing_profile_attributes.organization_attributes));
/** /**

View File

@ -1,5 +1,5 @@
import { Plan } from './plan'; import { Plan } from './plan';
import { TDateISO } from '../typings/date-iso'; import { TDateISO, TDateISODate } from '../typings/date-iso';
export enum UserRole { export enum UserRole {
Member = 'member', Member = 'member',
@ -69,7 +69,7 @@ export interface User {
statistic_profile_attributes: { statistic_profile_attributes: {
id: number, id: number,
gender: string, gender: string,
birthday: TDateISO birthday: TDateISODate
}, },
subscribed_plan: Plan, subscribed_plan: Plan,
subscription: { subscription: {