Skip to content

Commit

Permalink
SBERDOMA-431 fixed typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAL committed Jun 24, 2021
1 parent b55fcb5 commit db005a4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ interface IContactSyncedAutocompleteFieldsProps {
checked?: boolean,
// Used for autocomplete
contacts: TContact[],
displayMinusButton: boolean,
onClickMinusButton: () => void,
displayMinusButton?: boolean,
onClickMinusButton?: () => void,
}

/**
* When a phone will be selected, "Name" field should reflect appropriate value
* for selected contact and vise-versa.
*/
export const ContactSyncedAutocompleteFields: React.FC<IContactSyncedAutocompleteFieldsProps> = ({
const ContactSyncedAutocompleteFields: React.FC<IContactSyncedAutocompleteFieldsProps> = ({
initialValue,
onChange,
onChecked,
Expand Down Expand Up @@ -148,4 +148,10 @@ export const ContactSyncedAutocompleteFields: React.FC<IContactSyncedAutocomplet

ContactSyncedAutocompleteFields.defaultProps = {
displayMinusButton: false,
// eslint-disable-next-line @typescript-eslint/no-empty-function
onClickMinusButton: () => {},
}

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

const validations = useTicketValidations()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React, { useEffect, useMemo, useRef, useState } from 'react'
import { Contact } from '../../utils/clientSchema'
import { ContactsEditor, IContactEditorProps } from './index'
import { ContactFields, ContactsEditor, IContactEditorProps } from './index'
import { IContactUIState } from '../../utils/clientSchema/Contact'

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

interface IContactsEditorHookResult {
createContact: (organization: string, property: string, unitName: string) => Promise<void>,
createContact: (organization: string, property: string, unitName: string) => Promise<IContactUIState>,
ContactsEditorComponent: React.FC<IContactEditorProps>,
}

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

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

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

const handleChangeContact = (values, isNew) => {
Expand All @@ -42,7 +45,8 @@ export const useContactsEditorHook = ({ organization }: IContactsEditorHookArgs)
if (shouldCreateContactRef.current) {
try {
return await createContactAction({
...contactFieldsRef.current,
phone: contactFieldsRef.current.phone,
name: contactFieldsRef.current.name,
organization,
property,
unitName,
Expand Down
5 changes: 4 additions & 1 deletion apps/condo/domains/contact/utils/clientSchema/Contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const RELATIONS = ['organization', 'property']

export interface IContactUIState extends Contact {
id: string
// TODO(codegen): write IContactUIState or extends it from
unitName?: string
email?: string
phone: string
name: string
}

function convertToUIState (item: Contact): IContactUIState {
Expand Down
4 changes: 2 additions & 2 deletions apps/condo/domains/ticket/utils/clientSchema/Ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export interface ITicketFormState {
operator?: string
client?: string
contact?: string
clientPhone: string
clientName: string
clientPhone?: string
clientName?: string
}

function convertToUIFormState (state: ITicketUIState): ITicketFormState | undefined {
Expand Down

0 comments on commit db005a4

Please sign in to comment.