Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(condo): DOMA-6936 added column "Is verified" for contacts import #3865

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions apps/condo/domains/contact/hooks/useImporterFunctions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ContactCreateInput } from '@app/condo/schema'
import get from 'lodash/get'
import isNull from 'lodash/isNull'
import { useEffect, useRef } from 'react'

import { useApolloClient } from '@open-condo/next/apollo'
Expand All @@ -23,6 +25,13 @@ const { normalizePhone } = require('@condo/domains/common/utils/phone')

const SPLIT_PATTERN = /[,;.]+/g

const normalizeBooleanValue = (value: string, yes: string, no: string) => {
const VALID_VALUES = [yes.toLowerCase(), no.toLowerCase(), '']
const valueInLowerCase = value.trim().toLowerCase()
if (!VALID_VALUES.includes(valueInLowerCase)) return null
return valueInLowerCase === yes.toLowerCase()
}

const parsePhones = (phones: string) => {
const clearedPhones = phones.replace(/[^0-9+,;.]/g, '')
const splitPhones = clearedPhones.split(SPLIT_PATTERN)
Expand All @@ -46,19 +55,23 @@ export const useImporterFunctions = (): [Columns, RowNormalizer, RowValidator, O
const IncorrectUnitTypeMessage = intl.formatMessage({ id: 'errors.import.EmptyUnitType' })
const IncorrectEmailMessage = intl.formatMessage({ id: 'errors.import.IncorrectEmailFormat' })
const IncorrectPhonesMessage = intl.formatMessage({ id: 'errors.import.IncorrectPhonesFormat' })
const IncorrectIsVerifiedMessage = intl.formatMessage({ id: 'errors.import.IncorrectIsVerifiedFormat' })
const AlreadyCreatedContactMessage = intl.formatMessage({ id: 'errors.import.AlreadyCreatedContact' })
const AddressTitle = intl.formatMessage({ id: 'contact.import.column.Address' })
const UnitTitle = intl.formatMessage({ id: 'contact.import.column.Unit' })
const PhoneTitle = intl.formatMessage({ id: 'contact.import.column.Phone' })
const NameTitle = intl.formatMessage({ id: 'contact.import.column.Name' })
const EmailTitle = intl.formatMessage({ id: 'contact.import.column.Email' })
const RoleTitle = intl.formatMessage({ id: 'contact.import.column.Role' })
const IsVerifiedTitle = intl.formatMessage({ id: 'contact.import.column.IsVerified' })
const UnitTypeTitle = intl.formatMessage({ id: 'contact.import.column.UnitType' })
const FlatUnitTypeValue = intl.formatMessage({ id: 'pages.condo.ticket.field.unitType.flat' })
const ParkingUnitTypeValue = intl.formatMessage({ id: 'pages.condo.ticket.field.unitType.parking' })
const ApartmentUnitTypeValue = intl.formatMessage({ id: 'pages.condo.ticket.field.unitType.apartment' })
const WarehouseUnitTypeValue = intl.formatMessage({ id: 'pages.condo.ticket.field.unitType.warehouse' })
const CommercialUnitTypeValue = intl.formatMessage({ id: 'pages.condo.ticket.field.unitType.commercial' })
const NoMessage = intl.formatMessage({ id: 'No' })
const YesMessage = intl.formatMessage({ id: 'Yes' })

const userOrganization = useOrganization()
const client = useApolloClient()
Expand Down Expand Up @@ -99,6 +112,7 @@ export const useImporterFunctions = (): [Columns, RowNormalizer, RowValidator, O
{ name: NameTitle, type: 'string', required: true },
{ name: EmailTitle, type: 'string', required: false },
{ name: RoleTitle, type: 'string', required: false },
{ name: IsVerifiedTitle, type: 'string', required: false },
]

const contactNormalizer: RowNormalizer = async (row) => {
Expand All @@ -110,9 +124,10 @@ export const useImporterFunctions = (): [Columns, RowNormalizer, RowValidator, O
email: null,
unitType: null,
role: null,
isVerified: null,
}
if (row.length !== columns.length) return Promise.resolve({ row })
const [address, , unitType, phones, fullName, email, role] = row
const [address, , unitType, phones, fullName, email, role, isVerified] = row
email.value = email.value && String(email.value).trim().length ? String(email.value).trim() : undefined

const unitTypeValue = String(get(unitType, 'value', '')).trim().toLowerCase()
Expand All @@ -130,6 +145,7 @@ export const useImporterFunctions = (): [Columns, RowNormalizer, RowValidator, O
if (roleValue) {
addons.role = String(roleValue).trim().toLowerCase()
}
addons.isVerified = normalizeBooleanValue(String(get(isVerified, 'value', '')), YesMessage, NoMessage)

return addressApi.getSuggestions(String(address.value)).then(result => {
const suggestion = get(result, ['suggestions', 0])
Expand Down Expand Up @@ -185,6 +201,9 @@ export const useImporterFunctions = (): [Columns, RowNormalizer, RowValidator, O
}
}

const isVerified = get(row, ['addons', 'isVerified'])
if (isNull(isVerified)) errors.push(IncorrectIsVerifiedMessage)

const { data } = await searchContacts(client, {
organizationId: userOrganizationIdRef.current,
propertyId: row.addons.property,
Expand Down Expand Up @@ -217,14 +236,15 @@ export const useImporterFunctions = (): [Columns, RowNormalizer, RowValidator, O
continue
}

const contactData = {
const contactData: ContactCreateInput = {
organization: { connect: { id: userOrganizationIdRef.current } },
property: { connect: { id: String(row.addons.property) } },
unitName,
unitType: row.addons.unitType,
phone: phone,
name: row.addons.fullName,
email: row.addons.email,
isVerified: row.addons.isVerified,
}

const role = get(row, ['addons', 'role'])
Expand Down
2 changes: 2 additions & 0 deletions apps/condo/lang/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@
"contact.import.column.Name": "Full name",
"contact.import.column.Email": "Email",
"contact.import.column.Role": "Role",
"contact.import.column.IsVerified": "Is verified",
"contact.form.prompt.title": "Do not save contact?",
"contact.form.prompt.message": "Contact will not be saved if you leave the page.",
"focus.tooltipText": "Now you can go to next step",
Expand Down Expand Up @@ -1774,6 +1775,7 @@
"errors.import.AlreadyCreatedContact": "Such a contact already exists in this unit",
"errors.import.IncorrectContactRole": "Incorrect contact role. Please use one of the following list: {rolesList}",
"errors.import.IncorrectIsResidentTicketFormat": "The field «Is resident ticket» is filled incorrectly",
"errors.import.IncorrectIsVerifiedFormat": "The field «Is verified» is filled incorrectly",
"errors.import.date": "Incorrect date format in column \"{columnName}\". Use a value of type String in the format: \"{format}\"",
"errors.import.IncorrectPhoneAndFullNameForResidentTicket": "Incorrect resident data (\"Full Name\", \"Phone\")",
"errors.import.isEmptyDetails": "The \"Details\" field must be filled",
Expand Down
2 changes: 2 additions & 0 deletions apps/condo/lang/ru/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@
"contact.import.column.Name": "ФИО",
"contact.import.column.Email": "E-mail",
"contact.import.column.Role": "Роль",
"contact.import.column.IsVerified": "Верифицирован",
"contact.form.prompt.title": "Не сохранять контакт?",
"contact.form.prompt.message": "Контакт не сохранится, если вы уйдете со страницы.",
"focus.tooltipText": "Теперь вы можете перейти к следующему шагу",
Expand Down Expand Up @@ -1774,6 +1775,7 @@
"errors.import.AlreadyCreatedContact": "Такой контакт уже существует в этой квартире",
"errors.import.IncorrectContactRole": "Неверная роль. Используйте роли из списка: {rolesList}",
"errors.import.IncorrectIsResidentTicketFormat": "Поле «Заявка от жителя» заполнено некорректно",
"errors.import.IncorrectIsVerifiedFormat": "Поле «Верифицирован» заполнено некорректно",
"errors.import.date": "Неверное значение даты в столбце \"{columnName}\". Используйте значение с типом Строка в формате \"{format}\"",
"errors.import.IncorrectPhoneAndFullNameForResidentTicket": "Некорректные данные жителя (\"ФИО\", \"Номер телефона\")",
"errors.import.isEmptyDetails": "Поле \"Описание проблемы\" должно быть заполнено",
Expand Down
Binary file modified apps/condo/public/contact-import-example-en.xlsx
Binary file not shown.
Binary file modified apps/condo/public/contact-import-example-ru.xlsx
Binary file not shown.
Loading