Skip to content

Commit 6e344e6

Browse files
authored
fix(condo): DOMA-12707 contact table bugs (#7039)
* fix(condo): DOMA-12707 update submodules and enhance contact management features * fix(condo): DOMA-12707 ensure safe access to API methods in contact management components * fix(condo): DOMA-12707 update submodule and refactor table component event handlers for improved pagination and row selection management * fix(condo): DOMA-12707 refetch contact after import * fix(condo): DOMA-12707 update useTableSearch hook to include setSearch function and adjust contact page integration * fix(condo): DOMA-12707 refine route change handling in contact page to reset table state based on URL query * fix(condo): DOMA-12707 update submodule callcenter to latest commit
1 parent 4bc37c0 commit 6e344e6

File tree

13 files changed

+218
-152
lines changed

13 files changed

+218
-152
lines changed

apps/callcenter

apps/condo/domains/common/hooks/useSearch.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import debounce from 'lodash/debounce'
22
import get from 'lodash/get'
33
import isEqual from 'lodash/isEqual'
44
import { useRouter } from 'next/router'
5-
import { useCallback, useEffect, useMemo, useState } from 'react'
5+
import { Dispatch, RefObject, SetStateAction, useCallback, useEffect, useMemo, useState } from 'react'
66

77
import { TableRef } from '@open-condo/ui/src'
88

@@ -11,6 +11,7 @@ import { getFiltersFromQuery, updateQuery } from '@condo/domains/common/utils/he
1111

1212

1313
type UseSearchOutputType = [string, (search: string) => void, () => void]
14+
export type UseTableSearchOutputType = [string, (search: string) => void, Dispatch<SetStateAction<string>>, () => void]
1415

1516
/**
1617
* @deprecated use useTableSearch
@@ -44,12 +45,14 @@ export const useSearch = <F> (debounceTime: number = 400): UseSearchOutputType =
4445
return [search, handleSearchChange, handleResetSearch]
4546
}
4647

47-
export const useTableSearch = (tableRef: TableRef, debounceTime: number = 400): UseSearchOutputType => {
48+
export const useTableSearch = (tableRef: RefObject<TableRef | null>, debounceTime: number = 400): UseTableSearchOutputType => {
4849
const [search, setSearch] = useState<string>('')
4950

5051
const searchChange = useMemo(() => debounce((value: string) => {
51-
tableRef?.api?.setGlobalFilter(value)
52-
}, debounceTime), [tableRef?.api, debounceTime])
52+
if (tableRef.current?.api) {
53+
tableRef.current.api.setGlobalFilter(value)
54+
}
55+
}, debounceTime), [tableRef, debounceTime])
5356

5457
const handleSearchChange = useCallback((value: string): void => {
5558
setSearch(value)
@@ -61,5 +64,5 @@ export const useTableSearch = (tableRef: TableRef, debounceTime: number = 400):
6164
searchChange('')
6265
}, [searchChange])
6366

64-
return [search, handleSearchChange, handleResetSearch]
67+
return [search, handleSearchChange, setSearch, handleResetSearch]
6568
}

apps/condo/domains/contact/components/CreateContactForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export const CreateContactForm: React.FC = () => {
177177
})
178178

179179
client.cache.evict({ id: 'ROOT_QUERY', fieldName: 'allContacts' })
180+
client.cache.evict({ id: 'ROOT_QUERY', fieldName: '_allContactsMeta' })
180181
client.cache.gc()
181182

182183
if (redirectToClientCard) {

apps/condo/domains/contact/components/EditContactForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ export const EditContactForm: React.FC = () => {
124124
})
125125
}
126126
} else {
127-
await router.push('/contact')
127+
await router.push(`/contact/${contactId}`)
128128
}
129129

130130
client.cache.evict({ id: 'ROOT_QUERY', fieldName: 'allContacts' })
131+
client.cache.evict({ id: 'ROOT_QUERY', fieldName: '_allContactsMeta' })
131132
client.cache.gc()
132133
}, [client.cache, contactId, redirectToClientCard, router, updateContactMutation])
133134

apps/condo/domains/contact/hooks/useTableColumns.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const useTableColumns: UseTableColumns = (filterMetas) => {
3030
const PhoneMessage = intl.formatMessage({ id: 'Phone' })
3131
const IsVerifiedMessage = intl.formatMessage({ id: 'contact.column.header.isVerified' })
3232
const EmailMessage = intl.formatMessage({ id: 'Email' })
33+
const NoteMessage = intl.formatMessage({ id: 'contact.column.header.note' })
3334
const DeletedMessage = intl.formatMessage({ id: 'Deleted' })
3435
const YesMessage = intl.formatMessage({ id: 'Yes' })
3536
const NoMessage = intl.formatMessage({ id: 'No' })
@@ -71,6 +72,10 @@ export const useTableColumns: UseTableColumns = (filterMetas) => {
7172
(email, _, __, globalFilter) => getTableCellRenderer({ search: globalFilter, href: email ? `mailto:${email}` : undefined, ellipsis: true })(email ?? '—')
7273
, [])
7374

75+
const renderNote = useCallback<RenderTableCell<TData, TData['note']>>(
76+
(note, _, __, globalFilter) => getTableCellRenderer({ search: globalFilter, ellipsis: true })(note ?? '—')
77+
, [])
78+
7479

7580
return useMemo(() => {
7681
return [
@@ -149,6 +154,15 @@ export const useTableColumns: UseTableColumns = (filterMetas) => {
149154
initialSize: '10%',
150155
initialVisibility: false,
151156
},
157+
{
158+
header: NoteMessage,
159+
dataKey: 'note',
160+
id: 'note',
161+
render: renderNote,
162+
filterComponent: getFilterComponentByKey(filterMetas, 'note'),
163+
initialSize: '10%',
164+
initialVisibility: false,
165+
},
152166
]
153167
}, [
154168
filterMetas,
@@ -161,6 +175,7 @@ export const useTableColumns: UseTableColumns = (filterMetas) => {
161175
IsVerifiedMessage,
162176
UnitTypeMessage,
163177
EmailMessage,
178+
NoteMessage,
164179
renderName,
165180
renderRole,
166181
renderAddress,
@@ -170,5 +185,6 @@ export const useTableColumns: UseTableColumns = (filterMetas) => {
170185
renderEmail,
171186
renderIsVerified,
172187
renderDate,
188+
renderNote,
173189
])
174190
}

apps/condo/domains/contact/hooks/useTableFilters.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const filterAddress = getFilter(['property', 'id'], 'array', 'string', 'in')
2525
const filterRole = getFilter(['role', 'id'], 'array', 'string', 'in')
2626
const filterIsVerified = getBooleanFilter(['isVerified'])
2727
const filterCreatedAtRange = getDayRangeFilter('createdAt')
28+
const filterNote = getStringContainsFilter('note')
2829

2930
type UseContactsTableFilters = () => Array<TableFiltersMeta<ContactWhereInput>>
3031

@@ -40,6 +41,7 @@ export const useContactsTableFilters: UseContactsTableFilters = () => {
4041
const YesMessage = intl.formatMessage({ id: 'Yes' })
4142
const NoMessage = intl.formatMessage({ id: 'No' })
4243
const SelectMessage = intl.formatMessage({ id: 'Select' })
44+
const NoteMessage = intl.formatMessage({ id: 'contact.column.header.note' })
4345

4446
const { organization } = useOrganization()
4547
const organizationId = organization?.id || null
@@ -180,6 +182,16 @@ export const useContactsTableFilters: UseContactsTableFilters = () => {
180182
},
181183
},
182184
},
185+
{
186+
keyword: 'note',
187+
filters: [filterNote],
188+
component: {
189+
type: ComponentType.Input,
190+
props: {
191+
placeholder: NoteMessage,
192+
},
193+
},
194+
},
183195
]
184196
}, [
185197
EnterAddressMessage,
@@ -196,5 +208,6 @@ export const useContactsTableFilters: UseContactsTableFilters = () => {
196208
organizationId,
197209
unitTypeOptions,
198210
contactRolesLoading,
211+
NoteMessage,
199212
])
200213
}

apps/condo/lang/ru/ru.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@
783783
"contact.column.header.isVerified": "Верифицирован",
784784
"contact.column.header.email": "E-mail",
785785
"contact.column.header.ownershipPercentage": "Доля собственности",
786-
"contact.column.header.note": "Примечание",
786+
"contact.column.header.note": "Заметка",
787787
"contact.column.header.communityFee": "Коммунальные платежи",
788788
"contact.form.prompt.message": "Контакт не сохранится, если вы уйдете со страницы.",
789789
"contact.form.prompt.title": "Не сохранять контакт?",

0 commit comments

Comments
 (0)