2023-01-10 23:45:33 +00:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { useForm } from 'react-hook-form';
|
2022-12-07 03:11:25 +00:00
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
2023-01-10 23:45:33 +00:00
|
|
|
import { ControlledFormTextInput } from '../../containers/TextInput';
|
|
|
|
|
|
|
|
interface ISubmit {
|
|
|
|
avatarUrl: string;
|
|
|
|
}
|
2022-12-07 21:02:16 +00:00
|
|
|
|
|
|
|
const AvatarUrl = ({ submit }: { submit: (value: string) => void }) => {
|
2023-01-10 23:45:33 +00:00
|
|
|
const {
|
|
|
|
control,
|
2023-01-14 03:09:16 +00:00
|
|
|
formState: { isDirty },
|
2023-01-10 23:45:33 +00:00
|
|
|
getValues
|
2023-01-14 03:09:16 +00:00
|
|
|
} = useForm<ISubmit>({ mode: 'onChange', defaultValues: { avatarUrl: '' } });
|
2023-01-10 23:45:33 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-01-14 03:09:16 +00:00
|
|
|
if (isDirty) {
|
2023-01-10 23:45:33 +00:00
|
|
|
const { avatarUrl } = getValues();
|
|
|
|
submit(avatarUrl);
|
|
|
|
} else {
|
|
|
|
submit('');
|
2022-12-07 21:02:16 +00:00
|
|
|
}
|
2023-01-14 03:09:16 +00:00
|
|
|
}, [isDirty]);
|
2022-12-07 03:11:25 +00:00
|
|
|
|
|
|
|
return (
|
2023-01-10 23:45:33 +00:00
|
|
|
<ControlledFormTextInput
|
|
|
|
control={control}
|
|
|
|
name='avatarUrl'
|
2022-12-07 03:11:25 +00:00
|
|
|
label={I18n.t('Avatar_Url')}
|
2022-12-07 23:17:08 +00:00
|
|
|
placeholder={I18n.t('insert_Avatar_URL')}
|
2022-12-07 03:11:25 +00:00
|
|
|
testID='change-avatar-view-avatar-url'
|
|
|
|
containerStyle={{ marginBottom: 0 }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AvatarUrl;
|