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

Fix types and reset input function

This commit is contained in:
vincent 2022-05-04 08:55:51 +02:00
parent cb5dd953ea
commit 2b67280fd6
2 changed files with 5 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import React, { useState, useReducer } from 'react'; 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 { FieldValues } from 'react-hook-form/dist/types/fields';
import { User } from '../../models/user'; import { User } from '../../models/user';
import { SocialNetwork } from '../../models/social-network'; import { SocialNetwork } from '../../models/social-network';
@ -10,11 +10,11 @@ import { useTranslation } from 'react-i18next';
interface EditSocialsProps<TFieldValues> { interface EditSocialsProps<TFieldValues> {
register: UseFormRegister<TFieldValues>, register: UseFormRegister<TFieldValues>,
resetField: UseFormResetField<User>, setValue: UseFormSetValue<User>,
networks: SocialNetwork[], networks: SocialNetwork[],
} }
export const EditSocials = <TFieldValues extends FieldValues>({ register, resetField, networks }: EditSocialsProps<TFieldValues>) => { export const EditSocials = <TFieldValues extends FieldValues>({ register, setValue, networks }: EditSocialsProps<TFieldValues>) => {
const { t } = useTranslation('shared'); const { t } = useTranslation('shared');
const initSelectedNetworks = networks.filter(el => el.url !== ''); const initSelectedNetworks = networks.filter(el => el.url !== '');
@ -27,7 +27,7 @@ export const EditSocials = <TFieldValues extends FieldValues>({ register, resetF
switch (action.type) { switch (action.type) {
case 'delete': case 'delete':
setSelectedNetworks(selectedNetworks.filter(el => el !== action.payload.network)); setSelectedNetworks(selectedNetworks.filter(el => el !== action.payload.network));
resetField(action.payload.field); setValue(action.payload.field, '');
return state.map(el => el === action.payload.network return state.map(el => el === action.payload.network
? { ...el, url: '' } ? { ...el, url: '' }
: el); : el);

View File

@ -1,4 +1,5 @@
import { User, UserRole } from '../models/user'; import { User, UserRole } from '../models/user';
import { supportedNetworks } from '../models/social-network';
export default class UserLib { export default class UserLib {
private user: User; private user: User;
@ -25,7 +26,6 @@ export default class UserLib {
*/ */
getUserSocialNetworks = (customer: User): {name: string, url: string}[] => { getUserSocialNetworks = (customer: User): {name: string, url: string}[] => {
const userNetworks = []; 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)) { for (const [name, url] of Object.entries(customer.profile)) {
supportedNetworks.includes(name) && userNetworks.push({ name, url }); supportedNetworks.includes(name) && userNetworks.push({ name, url });