From d9013c5d664bb022cd0b33936da9941195424c7b Mon Sep 17 00:00:00 2001 From: Vasiliy Kislov <64303474+VKislov@users.noreply.github.com> Date: Fri, 11 Aug 2023 12:54:27 +0500 Subject: [PATCH] feat(condo): DOMA-6331 push notification about the need to send meter readings (#3612) * feat(condo): DOMA-6331 push notification about the need to send meter readings * feat(condo): DOMA-6331 make push uniq by pattern userId, start or end period and current month * feat(condo): DOMA-6331 added push notification translates * feat(condo): DOMA-6331 change pattern of uniqKey to userId_startPeriodDay-endPeriodDay_(start/end). fix tests * feat(condo): DOMA-6330 added routing on index meter page * fix(condo): DOMA-6331 fix cron task config * fix(condo): DOMA-6633 fix text of btn on create period page * fix(condo): DOMA-6631 fix rerender of selects start and end of period * fix(condo): DOMA-6630 add placeholder if chosen period for all organization * fix(condo): DOMA-6331 disable isOrganization checkbox when org period has already been created * fix(condo): DOMA-6331 makemigrations and types * fix(condo): DOMA-6330 fix formValuesToMutationDataPreprocessor on update action * fix(condo): DOMA-6331 try to fix error * fix(condo): DOMA-6331 fix checkIsDateInPeriod util * fix(condo): DOMA-6331 fix dayjs locale * fix(condo): DOMA-6816 fix METER_SUBMIT_READINGS_REMINDER_END_PERIOD and push by deleted meters and periods * fix(condo): DOMA-6815 fix connect deleted meter from deleted resident to not deleted resident with same accountNumber * fix(condo): DOMA-6331 some code improvements * chore(condo): DOMA-6331 rebase & regenerate migration --- .../components/CreateMeterReadingsForm.tsx | 2 +- .../components/MeterReportingPeriodForm.tsx | 25 ++-- apps/condo/domains/meter/hooks/useFilters.tsx | 4 +- ...endSubmitMeterReadingsPushNotifications.js | 114 +++++++++++++----- ...bmitMeterReadingsPushNotifications.spec.js | 94 ++++++++++++++- ...ubmitMeterReadingsPushNotificationsTask.js | 2 +- .../tasks/sendVerificationDateReminder.js | 8 +- .../notification/constants/constants.js | 24 ++++ apps/condo/lang/en/en.json | 9 +- .../default.njk | 1 + .../push.njk | 1 + .../sms.njk | 1 + .../default.njk | 1 + .../push.njk | 1 + .../sms.njk | 1 + .../default.njk | 1 + .../push.njk | 1 + .../sms.njk | 1 + .../default.njk | 1 + .../push.njk | 1 + .../sms.njk | 1 + apps/condo/lang/ru/ru.json | 7 ++ ...ter_notificationusersetting_messagetype.js | 26 ++++ apps/condo/pages/meter/index.tsx | 29 ++++- .../meter/reportingPeriod/[id]/update.tsx | 4 +- .../pages/meter/reportingPeriod/create.tsx | 4 +- apps/condo/schema.graphql | 54 ++++++++- apps/condo/schema.ts | 54 ++++++++- 28 files changed, 417 insertions(+), 55 deletions(-) create mode 100644 apps/condo/lang/en/messages/METER_SUBMIT_READINGS_REMINDER_END_PERIOD/default.njk create mode 100644 apps/condo/lang/en/messages/METER_SUBMIT_READINGS_REMINDER_END_PERIOD/push.njk create mode 100644 apps/condo/lang/en/messages/METER_SUBMIT_READINGS_REMINDER_END_PERIOD/sms.njk create mode 100644 apps/condo/lang/en/messages/METER_SUBMIT_READINGS_REMINDER_START_PERIOD/default.njk create mode 100644 apps/condo/lang/en/messages/METER_SUBMIT_READINGS_REMINDER_START_PERIOD/push.njk create mode 100644 apps/condo/lang/en/messages/METER_SUBMIT_READINGS_REMINDER_START_PERIOD/sms.njk create mode 100644 apps/condo/lang/ru/messages/METER_SUBMIT_READINGS_REMINDER_END_PERIOD/default.njk create mode 100644 apps/condo/lang/ru/messages/METER_SUBMIT_READINGS_REMINDER_END_PERIOD/push.njk create mode 100644 apps/condo/lang/ru/messages/METER_SUBMIT_READINGS_REMINDER_END_PERIOD/sms.njk create mode 100644 apps/condo/lang/ru/messages/METER_SUBMIT_READINGS_REMINDER_START_PERIOD/default.njk create mode 100644 apps/condo/lang/ru/messages/METER_SUBMIT_READINGS_REMINDER_START_PERIOD/push.njk create mode 100644 apps/condo/lang/ru/messages/METER_SUBMIT_READINGS_REMINDER_START_PERIOD/sms.njk create mode 100644 apps/condo/migrations/20230810172249-0306_alter_notificationusersetting_messagetype.js diff --git a/apps/condo/domains/meter/components/CreateMeterReadingsForm.tsx b/apps/condo/domains/meter/components/CreateMeterReadingsForm.tsx index 6433038099b..ce80aadabca 100644 --- a/apps/condo/domains/meter/components/CreateMeterReadingsForm.tsx +++ b/apps/condo/domains/meter/components/CreateMeterReadingsForm.tsx @@ -493,7 +493,7 @@ export const CreatePropertyMeterReadingsForm = ({ organization, role }) => { const createMeterReadingAction = PropertyMeterReading.useCreate({ source: { connect: { id: CRM_METER_READING_SOURCE_ID } }, }, async () => { - await router.push(`/meter?meterType=${METER_PAGE_TYPES.propertyMeter}`) + await router.push(`/meter?tab=${METER_PAGE_TYPES.propertyMeter}`) }) const handleSubmit = useCallback(async (values) => { diff --git a/apps/condo/domains/meter/components/MeterReportingPeriodForm.tsx b/apps/condo/domains/meter/components/MeterReportingPeriodForm.tsx index 9bfba2cf567..4bf8d86c784 100644 --- a/apps/condo/domains/meter/components/MeterReportingPeriodForm.tsx +++ b/apps/condo/domains/meter/components/MeterReportingPeriodForm.tsx @@ -4,6 +4,7 @@ import { jsx } from '@emotion/react' import { Col, Form, Row, Typography } from 'antd' import get from 'lodash/get' import isEmpty from 'lodash/isEmpty' +import isNil from 'lodash/isNil' import { useRouter } from 'next/router' import { Rule } from 'rc-field-form/lib/interface' import React, { CSSProperties, useCallback, useEffect, useMemo, useRef, useState } from 'react' @@ -60,11 +61,14 @@ export const MeterReportingPeriodForm: React.FC = ({ const OrMessage = intl.formatMessage({ id: 'Or' }) const DeleteButtonLabel = intl.formatMessage({ id: 'Delete' }) const AddressLabel = intl.formatMessage({ id: 'field.Address' }) - const SubmitButtonLabel = intl.formatMessage({ id: 'ApplyChanges' }) + const SubmitButtonApplyLabel = intl.formatMessage({ id: 'ApplyChanges' }) + const SubmitButtonCreateLabel = intl.formatMessage({ id: 'Create' }) const AddressPlaceholderMessage = intl.formatMessage({ id: 'placeholder.Address' }) const ErrorsContainerTitle = intl.formatMessage({ id: 'errorsContainer.requiredErrors' }) const StartLabel = intl.formatMessage({ id: 'pages.condo.meter.reportingPeriod.create.start' }) const FinishLabel = intl.formatMessage({ id: 'pages.condo.meter.reportingPeriod.create.finish' }) + const AddressPlaceholderLabel = intl.formatMessage({ id: 'pages.condo.meter.reportingPeriod.create.addressPlaceholder' }) + const AddressPlaceholderDefaultPeriodLabel = intl.formatMessage({ id: 'pages.condo.meter.reportingPeriod.create.addressPlaceholderIfDefaultPeriod' }) const IncorrectPeriodLabel = intl.formatMessage({ id: 'pages.condo.meter.reportingPeriod.create.incorrectPeriod' }) const OrganizationLabel = intl.formatMessage({ id: 'pages.condo.meter.reportingPeriod.create.organizationPeriod' }) const OrganizationTooltipMessage = intl.formatMessage({ id: 'pages.condo.meter.reportingPeriod.create.organizationTooltip' }) @@ -91,6 +95,7 @@ export const MeterReportingPeriodForm: React.FC = ({ const startNumberRef = useRef(formInitialValues.notifyStartDay) const finishNumberRef = useRef(formInitialValues.notifyEndDay) + const [selectRerender, execSelectRerender] = useState() const selectedPropertyIdRef = useRef(selectedPropertyId) useEffect(() => { @@ -135,11 +140,13 @@ export const MeterReportingPeriodForm: React.FC = ({ const handleStartChange = useCallback((value) => { startNumberRef.current = value + execSelectRerender(value) handleDayChange() }, []) const handleFinishChange = useCallback((value) => { finishNumberRef.current = value + execSelectRerender(value) handleDayChange() }, []) @@ -153,7 +160,6 @@ export const MeterReportingPeriodForm: React.FC = ({ error: periodsLoadingError, } = MeterReportingPeriod.useObjects({ where: { - property_is_null: false, organization: { id: organizationId }, }, }, @@ -161,7 +167,11 @@ export const MeterReportingPeriodForm: React.FC = ({ fetchPolicy: 'network-only', }) - const search = useMemo(() => searchOrganizationPropertyWithoutPropertyHint(organizationId, reportingPeriods.map(period => period.property.id)), + const hasOrganizationPeriod = Boolean(reportingPeriods.find(period => isNil(period.property) && !isNil(period.organization))) + + const periodsWithProperty = reportingPeriods.filter(period => !isNil(period.property)) + + const search = useMemo(() => searchOrganizationPropertyWithoutPropertyHint(organizationId, periodsWithProperty.map(period => period.property.id)), [organization, isPeriodsLoading]) const handelGQLInputChange = () => { @@ -189,8 +199,8 @@ export const MeterReportingPeriodForm: React.FC = ({ values.property = { connect: { id: selectedPropertyIdRef.current } } } values.isOrganizationPeriod = undefined - values.notifyStartDay = parseInt(values.notifyStartDay) - values.notifyEndDay = parseInt(values.notifyEndDay) + values.notifyStartDay = startNumberRef.current + values.notifyEndDay = finishNumberRef.current if (isCreateMode) { values.organization = { connect: { id: organizationId } } @@ -224,6 +234,7 @@ export const MeterReportingPeriodForm: React.FC = ({ = ({ > = ({ {...INPUT_LAYOUT_PROPS} labelAlign='left' required - shouldUpdate validateFirst >