From f99c060e4433940c43e9ca5c6b74809ddc8f58d4 Mon Sep 17 00:00:00 2001 From: Davide Frison <36330277+frisonisland@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:48:45 +0100 Subject: [PATCH] revert: undo changes introduce in react-18 migrations (#512) - we should approach the typing issue by adding some tests. Seems ChipItem and EditorAttachment are incompatible. We noticed the ContactInput is broken while doing manual tests --- src/view/editor/parts/editor-attendees.tsx | 70 ++++------------------ 1 file changed, 12 insertions(+), 58 deletions(-) diff --git a/src/view/editor/parts/editor-attendees.tsx b/src/view/editor/parts/editor-attendees.tsx index 360afddd..05f75c3e 100644 --- a/src/view/editor/parts/editor-attendees.tsx +++ b/src/view/editor/parts/editor-attendees.tsx @@ -5,17 +5,9 @@ */ import React, { ReactElement, useCallback, useEffect, useMemo, useState } from 'react'; -import { - Button, - ChipInput, - ChipInputProps, - ChipItem, - Container, - Row, - useSnackbar -} from '@zextras/carbonio-design-system'; +import { Button, ChipInput, Container, Row, useSnackbar } from '@zextras/carbonio-design-system'; import { useIntegratedComponent } from '@zextras/carbonio-shell-ui'; -import { find, map, reduce, reject, some } from 'lodash'; +import { find, map, reject, some } from 'lodash'; import { useTranslation } from 'react-i18next'; import styled from 'styled-components'; @@ -40,7 +32,6 @@ import { editEditorAttendees, editEditorOptionalAttendees } from '../../../store/slices/editor-slice'; -import { EditorChipAttendees } from '../../../types/store/invite'; type EditorAttendeesProps = { editorId: string; @@ -103,58 +94,21 @@ export const EditorAttendees = ({ editorId }: EditorAttendeesProps): ReactElemen }); }, [createSnackbar, sender, t]); - const isValueToAddAnObjectWithLabelType = ( - arg: unknown - ): arg is { label: string } & Partial => - !!arg && typeof arg === 'object' && 'label' in arg; - - const onAdd = useCallback['onAdd']>>( - (valueToAdd): ChipItem => { - if (valueToAdd) { - if (typeof valueToAdd === 'string') { - return { label: valueToAdd, value: { email: valueToAdd } }; - } - if (isValueToAddAnObjectWithLabelType(valueToAdd)) { - return { - value: { ...valueToAdd, email: valueToAdd.email ?? valueToAdd.label }, - ...valueToAdd - }; - } - } - throw new Error('invalid keywords received'); - }, - [] - ); - - const onChange = useCallback['onChange']>>( - (chips) => { - const attendeesToSave = reduce( - chips, - (acc, chip) => (chip.value ? [...acc, chip.value] : acc), - [] as Array - ); + const onChange = useCallback( + (value: any) => { dispatch( editEditorAttendees({ id: editorId, - attendees: attendeesToSave + attendees: value }) ); }, [dispatch, editorId] ); - const onOptionalsChange = useCallback< - NonNullable['onChange']> - >( - (chips) => { - const attendeesToSave = reduce( - chips, - (acc, chip) => (chip.value ? [...acc, chip.value] : acc), - [] as Array - ); - if (attendeesToSave.length) { - dispatch(editEditorOptionalAttendees({ id: editorId, optionalAttendees: attendeesToSave })); - } + const onOptionalsChange = useCallback( + (value: any) => { + dispatch(editEditorOptionalAttendees({ id: editorId, optionalAttendees: value })); }, [dispatch, editorId] ); @@ -218,9 +172,10 @@ export const EditorAttendees = ({ editorId }: EditorAttendeesProps): ReactElemen {integrationAvailable ? ( {integrationAvailable ? (