diff --git a/apps/condo/domains/contact/hooks/useImporterFunctions.tsx b/apps/condo/domains/contact/hooks/useImporterFunctions.tsx index 0c1e0a9d4f2..ae28390746b 100644 --- a/apps/condo/domains/contact/hooks/useImporterFunctions.tsx +++ b/apps/condo/domains/contact/hooks/useImporterFunctions.tsx @@ -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' @@ -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) @@ -46,6 +55,7 @@ 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' }) @@ -53,12 +63,15 @@ export const useImporterFunctions = (): [Columns, RowNormalizer, RowValidator, O 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() @@ -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) => { @@ -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() @@ -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]) @@ -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, @@ -217,7 +236,7 @@ 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, @@ -225,6 +244,7 @@ export const useImporterFunctions = (): [Columns, RowNormalizer, RowValidator, O phone: phone, name: row.addons.fullName, email: row.addons.email, + isVerified: row.addons.isVerified, } const role = get(row, ['addons', 'role']) diff --git a/apps/condo/lang/en/en.json b/apps/condo/lang/en/en.json index abdc40ead42..00210ea1432 100644 --- a/apps/condo/lang/en/en.json +++ b/apps/condo/lang/en/en.json @@ -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", @@ -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", diff --git a/apps/condo/lang/ru/ru.json b/apps/condo/lang/ru/ru.json index 8abcd7ece65..a577515b872 100644 --- a/apps/condo/lang/ru/ru.json +++ b/apps/condo/lang/ru/ru.json @@ -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": "Теперь вы можете перейти к следующему шагу", @@ -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": "Поле \"Описание проблемы\" должно быть заполнено", diff --git a/apps/condo/public/contact-import-example-en.xlsx b/apps/condo/public/contact-import-example-en.xlsx index 914c81553e8..fea35eb7dc2 100644 Binary files a/apps/condo/public/contact-import-example-en.xlsx and b/apps/condo/public/contact-import-example-en.xlsx differ diff --git a/apps/condo/public/contact-import-example-ru.xlsx b/apps/condo/public/contact-import-example-ru.xlsx index 9baf058ae4e..5f19b5c3a81 100644 Binary files a/apps/condo/public/contact-import-example-ru.xlsx and b/apps/condo/public/contact-import-example-ru.xlsx differ