mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-04-12 02:02:31 +02:00
Fix types and reset input function
This commit is contained in:
parent
e56a68221e
commit
07cb248187
@ -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);
|
||||||
|
@ -27,7 +27,7 @@ interface UserProfileFormProps {
|
|||||||
export const UserProfileForm: React.FC<UserProfileFormProps> = ({ action, size, user, className, onError }) => {
|
export const UserProfileForm: React.FC<UserProfileFormProps> = ({ action, size, user, className, onError }) => {
|
||||||
const { t } = useTranslation('shared');
|
const { t } = useTranslation('shared');
|
||||||
|
|
||||||
const { handleSubmit, register, resetField, control, formState } = useForm<User>({ defaultValues: { ...user } });
|
const { handleSubmit, register, setValue, control, formState } = useForm<User>({ defaultValues: { ...user } });
|
||||||
const output = useWatch<User>({ control });
|
const output = useWatch<User>({ control });
|
||||||
|
|
||||||
const [isOrganization, setIsOrganization] = React.useState<boolean>(user.invoicing_profile.organization !== null);
|
const [isOrganization, setIsOrganization] = React.useState<boolean>(user.invoicing_profile.organization !== null);
|
||||||
@ -112,7 +112,7 @@ export const UserProfileForm: React.FC<UserProfileFormProps> = ({ action, size,
|
|||||||
<h4>{t('app.shared.user_profile_form.account_networks')}</h4>
|
<h4>{t('app.shared.user_profile_form.account_networks')}</h4>
|
||||||
<EditSocials register={register}
|
<EditSocials register={register}
|
||||||
networks={userNetworks}
|
networks={userNetworks}
|
||||||
resetField={resetField} />
|
setValue={setValue} />
|
||||||
</div>
|
</div>
|
||||||
<div className="organization-data">
|
<div className="organization-data">
|
||||||
<h4>{t('app.shared.user_profile_form.organization_data')}</h4>
|
<h4>{t('app.shared.user_profile_form.organization_data')}</h4>
|
||||||
@ -139,7 +139,6 @@ export const UserProfileForm: React.FC<UserProfileFormProps> = ({ action, size,
|
|||||||
label={t('app.shared.user_profile_form.organization_address')} />
|
label={t('app.shared.user_profile_form.organization_address')} />
|
||||||
</div>}
|
</div>}
|
||||||
</div>
|
</div>
|
||||||
<button type="submit">go</button>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
@ -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 });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user