Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit db005a4

Browse files
committedJun 24, 2021
SBERDOMA-431 fixed typescript errors
1 parent b55fcb5 commit db005a4

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed
 

‎apps/condo/domains/contact/components/ContactsEditor/ContactSyncedAutocompleteFields.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ interface IContactSyncedAutocompleteFieldsProps {
2929
checked?: boolean,
3030
// Used for autocomplete
3131
contacts: TContact[],
32-
displayMinusButton: boolean,
33-
onClickMinusButton: () => void,
32+
displayMinusButton?: boolean,
33+
onClickMinusButton?: () => void,
3434
}
3535

3636
/**
3737
* When a phone will be selected, "Name" field should reflect appropriate value
3838
* for selected contact and vise-versa.
3939
*/
40-
export const ContactSyncedAutocompleteFields: React.FC<IContactSyncedAutocompleteFieldsProps> = ({
40+
const ContactSyncedAutocompleteFields: React.FC<IContactSyncedAutocompleteFieldsProps> = ({
4141
initialValue,
4242
onChange,
4343
onChecked,
@@ -148,4 +148,10 @@ export const ContactSyncedAutocompleteFields: React.FC<IContactSyncedAutocomplet
148148

149149
ContactSyncedAutocompleteFields.defaultProps = {
150150
displayMinusButton: false,
151+
// eslint-disable-next-line @typescript-eslint/no-empty-function
152+
onClickMinusButton: () => {},
153+
}
154+
155+
export {
156+
ContactSyncedAutocompleteFields,
151157
}

‎apps/condo/domains/contact/components/ContactsEditor/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const ContactsEditor: React.FC<IContactEditorProps> = (props) => {
8686
// with different set of prefetched contacts. For example, when a different unitName is selected,
8787
// manually typed information should not be lost.
8888
const [manuallyTypedContact, setManuallyTypedContact] = useState()
89-
const [displayEditableContactFields, setDisplayEditableContactFields] = useState()
89+
const [displayEditableContactFields, setDisplayEditableContactFields] = useState(false)
9090

9191
const validations = useTicketValidations()
9292

‎apps/condo/domains/contact/components/ContactsEditor/useContactsEditorHook.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import React, { useEffect, useMemo, useRef, useState } from 'react'
22
import { Contact } from '../../utils/clientSchema'
3-
import { ContactsEditor, IContactEditorProps } from './index'
3+
import { ContactFields, ContactsEditor, IContactEditorProps } from './index'
4+
import { IContactUIState } from '../../utils/clientSchema/Contact'
45

56
interface IContactsEditorHookArgs {
67
// Organization scope for contacts autocomplete and new contact, that can be created
78
organization: string,
89
}
910

1011
interface IContactsEditorHookResult {
11-
createContact: (organization: string, property: string, unitName: string) => Promise<void>,
12+
createContact: (organization: string, property: string, unitName: string) => Promise<IContactUIState>,
1213
ContactsEditorComponent: React.FC<IContactEditorProps>,
1314
}
1415

1516
export const useContactsEditorHook = ({ organization }: IContactsEditorHookArgs): IContactsEditorHookResult => {
1617
// Field value will be initialized only on user interaction.
1718
// In case of no interaction, no create action will be performed
18-
const [contactFields, setContactFields] = useState({})
19+
// @ts-ignore
20+
const [contactFields, setContactFields] = useState<ContactFields>({})
1921
const [shouldCreateContact, setShouldCreateContact] = useState(false)
2022

2123
// Closure of `createContact` will be broken, when it will be assigned to another constant outside of this hook
@@ -31,6 +33,7 @@ export const useContactsEditorHook = ({ organization }: IContactsEditorHookArgs)
3133
shouldCreateContactRef.current = shouldCreateContact
3234
}, [shouldCreateContact])
3335

36+
// @ts-ignore
3437
const createContactAction = Contact.useCreate({}, () => Promise.resolve())
3538

3639
const handleChangeContact = (values, isNew) => {
@@ -42,7 +45,8 @@ export const useContactsEditorHook = ({ organization }: IContactsEditorHookArgs)
4245
if (shouldCreateContactRef.current) {
4346
try {
4447
return await createContactAction({
45-
...contactFieldsRef.current,
48+
phone: contactFieldsRef.current.phone,
49+
name: contactFieldsRef.current.name,
4650
organization,
4751
property,
4852
unitName,

‎apps/condo/domains/contact/utils/clientSchema/Contact.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const RELATIONS = ['organization', 'property']
1515

1616
export interface IContactUIState extends Contact {
1717
id: string
18-
// TODO(codegen): write IContactUIState or extends it from
18+
unitName?: string
19+
email?: string
20+
phone: string
21+
name: string
1922
}
2023

2124
function convertToUIState (item: Contact): IContactUIState {

‎apps/condo/domains/ticket/utils/clientSchema/Ticket.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export interface ITicketFormState {
3333
operator?: string
3434
client?: string
3535
contact?: string
36-
clientPhone: string
37-
clientName: string
36+
clientPhone?: string
37+
clientName?: string
3838
}
3939

4040
function convertToUIFormState (state: ITicketUIState): ITicketFormState | undefined {

0 commit comments

Comments
 (0)
Please sign in to comment.