generated from 8iq/nodejs-hackathon-boilerplate-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(condo): DOMA-6736 schema MobileFeatureConfig with tests (#3662)
* feat(condo): DOMA-6736 schema MobileFeatureConfig with tests * fix(condo): DOMA-6736 change field name from ticketSubmittingIsEnabled to ticketSubmittingIsDisabled. Rm emergencyPhone field * fix(condo): DOMA-6736 fix imports * feat(condo): DOMA-6753 frontend of MobileFeatureConfig * fix(condo): DOMA-6736 schemaDoc of some field of MobileFeatureConfig * fix(condo): DOMA-6736 review fixes * feat(condo): DOMA-6736 added permission canManageMobileFeatureConfigs for manage access * fix(condo): DOMA-6736 rename onlyProgressionMeterReadingsIsEnabled to onlyGreaterThanPreviousMeterReadingIsEnabled * fix(condo): DOMA-6736 replace catchErrorFrom to expectToThrowGQLError * fix(condo): DOMA-6736 use valuePropName * fix(condo): DOMA-6736 add deletedAt filter * fix(condo): DOMA-6736 review fixes some optimization on front, rm redundant react state. add tests for support. move FF constants to common/constants/featureFlags. fix schemaDoc for meta * fix(condo): DOMA-6736 some code improvements * chore(condo): DOMA-6736 fix imports Co-authored-by: Alllex202 <[email protected]> --------
- Loading branch information
Showing
31 changed files
with
2,402 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
apps/condo/domains/common/components/settings/MobileFeatureConfigContent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Col, Row } from 'antd' | ||
import { Gutter } from 'antd/es/grid/row' | ||
import get from 'lodash/get' | ||
import React from 'react' | ||
|
||
import { useFeatureFlags } from '@open-condo/featureflags/FeatureFlagsContext' | ||
import { useOrganization } from '@open-condo/next/organization' | ||
|
||
import { CardsContainer } from '@condo/domains/common/components/Card/CardsContainer' | ||
import { SettingCardSkeleton } from '@condo/domains/common/components/settings/SettingCard' | ||
import { MOBILE_FEATURE_CONFIGURATION, TICKET_SUBMITTING_FORM_RESIDENT_MOBILE_APP, SUBMIT_ONLY_PROGRESSION_METER_READINGS } from '@condo/domains/common/constants/featureflags' | ||
import { | ||
OnlyProgressionMeterReadingsSettingCard, | ||
} from '@condo/domains/settings/components/ticketSubmitting/OnlyProgressionMeterReadingsSettingCard' | ||
import { TicketSubmittingSettingCard } from '@condo/domains/settings/components/ticketSubmitting/TicketSubmittingSettingCard' | ||
import { MobileFeatureConfig as MobileFeatureConfigAPI } from '@condo/domains/settings/utils/clientSchema' | ||
|
||
const CONTENT_GUTTER: Gutter | [Gutter, Gutter] = [0, 40] | ||
|
||
export const MobileFeatureConfigContent: React.FC = () => { | ||
const userOrganization = useOrganization() | ||
const userOrganizationId = get(userOrganization, ['organization', 'id'], null) | ||
const { obj: mobileConfig, loading } = MobileFeatureConfigAPI.useObject({ | ||
where: { | ||
organization: { id: userOrganizationId }, | ||
}, | ||
}) | ||
const { useFlag } = useFeatureFlags() | ||
const hasMobileFeatureConfigurationFeature = useFlag(MOBILE_FEATURE_CONFIGURATION) | ||
const hasTicketSubmittingSettingFeature = useFlag(TICKET_SUBMITTING_FORM_RESIDENT_MOBILE_APP) | ||
const hasOnlyProgressionMeterReadingsSettingFeature = useFlag(SUBMIT_ONLY_PROGRESSION_METER_READINGS) | ||
|
||
if (!hasMobileFeatureConfigurationFeature) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Row gutter={CONTENT_GUTTER}> | ||
<Col span={24}> | ||
<CardsContainer cardsPerRow={2}> | ||
{ | ||
!hasTicketSubmittingSettingFeature ? null : (loading | ||
? <SettingCardSkeleton/> | ||
: <TicketSubmittingSettingCard mobileConfig={mobileConfig}/>) | ||
} | ||
{ | ||
!hasOnlyProgressionMeterReadingsSettingFeature ? null : (loading | ||
? <SettingCardSkeleton /> | ||
: <OnlyProgressionMeterReadingsSettingCard mobileConfig={mobileConfig}/>) | ||
} | ||
</CardsContainer> | ||
</Col> | ||
</Row> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Generated by `createschema settings.MobileFeatureConfig 'organization:Relationship:Organization:CASCADE; emergencyPhone:Text; commonPhone:Text; onlyGreaterThanPreviousMeterReadingIsEnabled:Checkbox; meta:Json; ticketSubmittingIsEnabled:Checkbox'` | ||
*/ | ||
|
||
const { uniq, map, get } = require('lodash') | ||
|
||
const { throwAuthenticationError } = require('@open-condo/keystone/apolloErrorFormatter') | ||
const { find, getById } = require('@open-condo/keystone/schema') | ||
|
||
const { checkPermissionInUserOrganizationOrRelatedOrganization } = require('@condo/domains/organization/utils/accessSchema') | ||
const { queryOrganizationEmployeeFor, queryOrganizationEmployeeFromRelatedOrganizationFor } = require('@condo/domains/organization/utils/accessSchema') | ||
const { RESIDENT } = require('@condo/domains/user/constants/common') | ||
|
||
async function canReadMobileFeatureConfigs ({ authentication: { item: user } }) { | ||
if (!user) return throwAuthenticationError() | ||
if (user.deletedAt) return false | ||
|
||
if (user.isAdmin || user.isSupport) return {} | ||
|
||
if (user.type === RESIDENT) { | ||
const residents = await find('Resident', { user: { id: user.id }, deletedAt: null }) | ||
const organizations = uniq(map(residents, 'organization')) | ||
|
||
if (residents.length > 0) { | ||
return { | ||
organization: { | ||
id_in: organizations, | ||
deletedAt: null, | ||
}, | ||
deletedAt: null, | ||
} | ||
} | ||
return false | ||
} | ||
|
||
return { | ||
organization: { | ||
OR: [ | ||
queryOrganizationEmployeeFor(user.id), | ||
queryOrganizationEmployeeFromRelatedOrganizationFor(user.id), | ||
], | ||
}, | ||
} | ||
} | ||
|
||
async function canManageMobileFeatureConfigs (attrs) { | ||
const { authentication: { item: user }, originalInput, operation, itemId } = attrs | ||
if (!user) return throwAuthenticationError() | ||
if (user.deletedAt) return false | ||
if (user.type === RESIDENT) return false | ||
if (user.isAdmin || user.isSupport) return true | ||
|
||
let organizationId | ||
if (operation === 'create') { | ||
organizationId = get(originalInput, 'organization.connect.id') | ||
} | ||
if ( operation === 'update') { | ||
if (!itemId) return false | ||
|
||
const foundConfig = await getById('MobileFeatureConfig', itemId) | ||
if (!foundConfig) return false | ||
|
||
organizationId = get(foundConfig, 'organization') | ||
} | ||
|
||
return await checkPermissionInUserOrganizationOrRelatedOrganization(user.id, organizationId, 'canManageMobileFeatureConfigs') | ||
} | ||
|
||
/* | ||
Rules are logical functions that used for list access, and may return a boolean (meaning | ||
all or no items are available) or a set of filters that limit the available items. | ||
*/ | ||
module.exports = { | ||
canReadMobileFeatureConfigs, | ||
canManageMobileFeatureConfigs, | ||
} | ||
|
113 changes: 113 additions & 0 deletions
113
apps/condo/domains/settings/components/ticketSubmitting/OnlyProgressionMeterReadingsForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { MobileFeatureConfig as MobileFeatureConfigType } from '@app/condo/schema' | ||
import { Col, Form, Row } from 'antd' | ||
import { Gutter } from 'antd/es/grid/row' | ||
import get from 'lodash/get' | ||
import { useRouter } from 'next/router' | ||
import React, { useMemo, useState } from 'react' | ||
|
||
import { useIntl } from '@open-condo/next/intl' | ||
import { ActionBar, Button, Checkbox, Typography } from '@open-condo/ui' | ||
|
||
import { FormWithAction } from '@condo/domains/common/components/containers/FormList' | ||
import { MobileFeatureConfig } from '@condo/domains/settings/utils/clientSchema' | ||
|
||
const INPUT_LAYOUT_PROPS = { | ||
labelCol: { | ||
span: 24, | ||
md: 5, | ||
}, | ||
wrapperCol: { | ||
span: 24, | ||
md: 6, | ||
}, | ||
styled: { | ||
paddingBottom: '12px', | ||
}, | ||
colon: false, | ||
} | ||
const BIG_ROW_GUTTERS: [Gutter, Gutter] = [0, 60] | ||
const MIDDLE_ROW_GUTTERS: [Gutter, Gutter] = [0, 40] | ||
const SMALL_ROW_GUTTERS: [Gutter, Gutter] = [0, 20] | ||
|
||
interface ITicketSubmittingSettingsForm { | ||
mobileConfig?: MobileFeatureConfigType, | ||
userOrganizationId: string, | ||
} | ||
|
||
export const OnlyProgressionMeterReadingsForm: React.FC<ITicketSubmittingSettingsForm> = ({ mobileConfig, userOrganizationId }) => { | ||
const intl = useIntl() | ||
const SaveMessage = intl.formatMessage({ id: 'Save' }) | ||
const MessageAboutFeat = intl.formatMessage({ id: 'pages.condo.settings.mobileFeatureConfig.OnlyProgressionMeterReadings.messageAboutFeat' }) | ||
const EnableMessage = intl.formatMessage({ id: 'pages.condo.settings.mobileFeatureConfig.OnlyProgressionMeterReadings.isEnabled' }) | ||
|
||
const router = useRouter() | ||
|
||
const initialValues = { | ||
onlyGreaterThanPreviousMeterReadingIsEnabled: get(mobileConfig, 'onlyGreaterThanPreviousMeterReadingIsEnabled'), | ||
} | ||
|
||
const updateHook = MobileFeatureConfig.useUpdate({}, () => router.push('/settings?tab=mobileFeatureConfig')) | ||
const updateAction = async (data) => { | ||
await updateHook(data, mobileConfig) | ||
} | ||
const createAction = MobileFeatureConfig.useCreate({}, () => router.push('/settings?tab=mobileFeatureConfig')) | ||
const action = mobileConfig ? updateAction : createAction | ||
|
||
return useMemo(() => ( | ||
<FormWithAction | ||
initialValues={initialValues} | ||
action={action} | ||
colon={false} | ||
layout='horizontal' | ||
formValuesToMutationDataPreprocessor={(values) => { | ||
if (!mobileConfig) { | ||
values.organization = { connect: { id: userOrganizationId } } | ||
} | ||
return values | ||
}} | ||
> | ||
{({ handleSave, isLoading }) => ( | ||
<Row gutter={BIG_ROW_GUTTERS}> | ||
<Col span={24}> | ||
<Row gutter={MIDDLE_ROW_GUTTERS}> | ||
<Col span={24}> | ||
<Row gutter={SMALL_ROW_GUTTERS}> | ||
<Col span={24}> | ||
<Typography.Text >{MessageAboutFeat}</Typography.Text> | ||
</Col> | ||
<Col span={24}> | ||
<Form.Item | ||
name='onlyGreaterThanPreviousMeterReadingIsEnabled' | ||
label={EnableMessage} | ||
labelAlign='left' | ||
{...INPUT_LAYOUT_PROPS} | ||
valuePropName='checked' | ||
> | ||
<Checkbox/> | ||
</Form.Item> | ||
</Col> | ||
|
||
</Row> | ||
</Col> | ||
|
||
</Row> | ||
</Col> | ||
<Col span={24}> | ||
<ActionBar | ||
actions={[ | ||
<Button | ||
key='submit' | ||
onClick={handleSave} | ||
type='primary' | ||
loading={isLoading} | ||
> | ||
{SaveMessage} | ||
</Button>, | ||
]} | ||
/> | ||
</Col> | ||
</Row> | ||
)} | ||
</FormWithAction> | ||
), [action, mobileConfig]) | ||
} |
38 changes: 38 additions & 0 deletions
38
.../domains/settings/components/ticketSubmitting/OnlyProgressionMeterReadingsSettingCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { MobileFeatureConfig as MobileFeatureConfigType } from '@app/condo/schema' | ||
import get from 'lodash/get' | ||
import { useRouter } from 'next/router' | ||
import React, { useCallback } from 'react' | ||
|
||
import { useIntl } from '@open-condo/next/intl' | ||
import { Typography } from '@open-condo/ui' | ||
|
||
import { SettingCard } from '@condo/domains/common/components/settings/SettingCard' | ||
|
||
interface OnlyProgressionMeterReadingsSettingCardProps { | ||
mobileConfig?: MobileFeatureConfigType | ||
} | ||
|
||
const TICKET_DISABLING_SETTINGS_URL = '/settings/mobileFeatureConfig/onlyProgressionMeterReadings' | ||
|
||
export const OnlyProgressionMeterReadingsSettingCard: React.FC<OnlyProgressionMeterReadingsSettingCardProps> = ({ mobileConfig }) => { | ||
const intl = useIntl() | ||
const OnlyProgressionMeterReadingsTitle = intl.formatMessage({ id: 'pages.condo.settings.barItem.MobileFeatureConfig.OnlyProgressionMeterReadings.title' }) | ||
const OnlyProgressionMeterReadingsIsDisabledLabel = intl.formatMessage({ id: 'pages.condo.settings.barItem.MobileFeatureConfig.OnlyProgressionMeterReadings.isDisabled' }) | ||
const onlyGreaterThanPreviousMeterReadingIsEnabledLabel = intl.formatMessage({ id: 'pages.condo.settings.barItem.MobileFeatureConfig.OnlyProgressionMeterReadings.isEnabled' }) | ||
|
||
const router = useRouter() | ||
|
||
const handleClickCard = useCallback(() => { | ||
router.push(TICKET_DISABLING_SETTINGS_URL) | ||
}, [router]) | ||
|
||
const isEnabled = get(mobileConfig, 'onlyGreaterThanPreviousMeterReadingIsEnabled') | ||
|
||
return ( | ||
<SettingCard title={OnlyProgressionMeterReadingsTitle} onClick={handleClickCard}> | ||
<Typography.Text type='secondary' > | ||
{isEnabled ? onlyGreaterThanPreviousMeterReadingIsEnabledLabel : OnlyProgressionMeterReadingsIsDisabledLabel} | ||
</Typography.Text> | ||
</SettingCard> | ||
) | ||
} |
Oops, something went wrong.