diff --git a/app/frontend/src/javascript/components/socials/edit-socials.tsx b/app/frontend/src/javascript/components/socials/edit-socials.tsx index 8681f6c43..5ce637824 100644 --- a/app/frontend/src/javascript/components/socials/edit-socials.tsx +++ b/app/frontend/src/javascript/components/socials/edit-socials.tsx @@ -1,5 +1,5 @@ import React, { useState, useReducer } from 'react'; -import { UseFormRegister, UseFormResetField } from 'react-hook-form'; +import { UseFormRegister, UseFormSetValue } from 'react-hook-form'; import { FieldValues } from 'react-hook-form/dist/types/fields'; import { User } from '../../models/user'; import { SocialNetwork } from '../../models/social-network'; @@ -10,11 +10,11 @@ import { useTranslation } from 'react-i18next'; interface EditSocialsProps { register: UseFormRegister, - resetField: UseFormResetField, + setValue: UseFormSetValue, networks: SocialNetwork[], } -export const EditSocials = ({ register, resetField, networks }: EditSocialsProps) => { +export const EditSocials = ({ register, setValue, networks }: EditSocialsProps) => { const { t } = useTranslation('shared'); const initSelectedNetworks = networks.filter(el => el.url !== ''); @@ -27,7 +27,7 @@ export const EditSocials = ({ register, resetF switch (action.type) { case 'delete': setSelectedNetworks(selectedNetworks.filter(el => el !== action.payload.network)); - resetField(action.payload.field); + setValue(action.payload.field, ''); return state.map(el => el === action.payload.network ? { ...el, url: '' } : el); diff --git a/app/frontend/src/javascript/components/user/user-profile-form.tsx b/app/frontend/src/javascript/components/user/user-profile-form.tsx index 9eb4fe941..b3fe5cf43 100644 --- a/app/frontend/src/javascript/components/user/user-profile-form.tsx +++ b/app/frontend/src/javascript/components/user/user-profile-form.tsx @@ -27,7 +27,7 @@ interface UserProfileFormProps { export const UserProfileForm: React.FC = ({ action, size, user, className, onError }) => { const { t } = useTranslation('shared'); - const { handleSubmit, register, resetField, control, formState } = useForm({ defaultValues: { ...user } }); + const { handleSubmit, register, setValue, control, formState } = useForm({ defaultValues: { ...user } }); const output = useWatch({ control }); const [isOrganization, setIsOrganization] = React.useState(user.invoicing_profile.organization !== null); @@ -112,7 +112,7 @@ export const UserProfileForm: React.FC = ({ action, size,

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

+ setValue={setValue} />

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

@@ -139,7 +139,6 @@ export const UserProfileForm: React.FC = ({ action, size, label={t('app.shared.user_profile_form.organization_address')} />
} - ); diff --git a/app/frontend/src/javascript/lib/user.ts b/app/frontend/src/javascript/lib/user.ts index f74f6f74b..3115621c9 100644 --- a/app/frontend/src/javascript/lib/user.ts +++ b/app/frontend/src/javascript/lib/user.ts @@ -1,4 +1,5 @@ import { User, UserRole } from '../models/user'; +import { supportedNetworks } from '../models/social-network'; export default class UserLib { private user: User; @@ -25,7 +26,6 @@ export default class UserLib { */ getUserSocialNetworks = (customer: User): {name: string, url: string}[] => { const userNetworks = []; - const supportedNetworks = ['facebook', 'twitter', 'viadeo', 'linkedin', 'instagram', 'youtube', 'vimeo', 'dailymotion', 'github', 'echosciences', 'pinterest', 'lastfm', 'flickr']; for (const [name, url] of Object.entries(customer.profile)) { supportedNetworks.includes(name) && userNetworks.push({ name, url });