generated from 8iq/nodejs-hackathon-boilerplate-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 26
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-9988 add ux property gate before news item is creat…
…ed (#5193) * feat(condo): add ux property gate before news item is created * fix(condo): remove console.log
- Loading branch information
1 parent
ecb4aac
commit f1001b3
Showing
12 changed files
with
140 additions
and
26 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
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
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 |
---|---|---|
@@ -1,24 +1,36 @@ | ||
import get from 'lodash/get' | ||
import Head from 'next/head' | ||
import React from 'react' | ||
|
||
import { useIntl } from '@open-condo/next/intl' | ||
import { useOrganization } from '@open-condo/next/organization' | ||
import { Typography } from '@open-condo/ui' | ||
|
||
import { AccessDeniedPage } from '@condo/domains/common/components/containers/AccessDeniedPage' | ||
import { PageHeader, PageWrapper, PageContent } from '@condo/domains/common/components/containers/BaseLayout' | ||
import LoadingOrErrorPage from '@condo/domains/common/components/containers/LoadingOrErrorPage' | ||
import { EmptyListContent } from '@condo/domains/common/components/EmptyListContent' | ||
import { NewsForm } from '@condo/domains/news/components/NewsForm' | ||
import { NewsReadAndManagePermissionRequired } from '@condo/domains/news/components/PageAccess' | ||
import { useNewsItemsAccess } from '@condo/domains/news/hooks/useNewsItemsAccess' | ||
import { Property } from '@condo/domains/property/utils/clientSchema' | ||
|
||
export interface ICreateNewsPage extends React.FC { | ||
headerAction?: JSX.Element | ||
requiredAccess?: React.FC | ||
} | ||
|
||
const CreateNewsPageContent: React.FC = () => { | ||
interface ICreateNewsPageContentProps { | ||
propertiesCount?: number | ||
canManage?: boolean | ||
} | ||
|
||
const CreateNewsPageContent: React.FC<ICreateNewsPageContentProps> = ({ propertiesCount, canManage }) => { | ||
const intl = useIntl() | ||
const PageTitle = intl.formatMessage({ id: 'news.create.title' }) | ||
const PropertyGateLabel = intl.formatMessage({ id: 'pages.condo.news.index.propertyGate.header' }) | ||
const PropertyGateMessage = intl.formatMessage({ id: 'pages.condo.news.index.propertyGate.title' }) | ||
const PropertyGateButtonLabel = intl.formatMessage({ id: 'pages.condo.property.index.CreatePropertyButtonLabel' }) | ||
|
||
return ( | ||
<> | ||
|
@@ -28,7 +40,18 @@ const CreateNewsPageContent: React.FC = () => { | |
<PageWrapper> | ||
<PageHeader title={<Typography.Title>{PageTitle}</Typography.Title>} spaced/> | ||
<PageContent> | ||
<NewsForm actionName='create'/> | ||
{ propertiesCount !== 0 ? | ||
<NewsForm actionName='create'/> | ||
: | ||
<EmptyListContent | ||
image='/dino/[email protected]' | ||
label={PropertyGateLabel} | ||
message={PropertyGateMessage} | ||
createRoute='/property/create?next=/news/create&skipTourModal=true' | ||
createLabel={PropertyGateButtonLabel} | ||
accessCheck={canManage} | ||
/> | ||
} | ||
</PageContent> | ||
</PageWrapper> | ||
</> | ||
|
@@ -38,15 +61,34 @@ const CreateNewsPageContent: React.FC = () => { | |
const CreateNewsPage: ICreateNewsPage = () => { | ||
const { canManage, isLoading: isAccessLoading } = useNewsItemsAccess() | ||
|
||
const intl = useIntl() | ||
const ServerErrorMsg = intl.formatMessage({ id: 'ServerError' }) | ||
|
||
const { organization } = useOrganization() | ||
|
||
const { | ||
count: propertiesCount, | ||
loading: propertiesLoading, | ||
error: propertiesError, | ||
} = Property.useCount({ where: { organization: { id: get(organization, 'id') } }, first: 1 }) | ||
|
||
const loading = isAccessLoading || propertiesLoading | ||
const error = propertiesError | ||
|
||
if (loading || error) { | ||
const errorToPrint = error ? ServerErrorMsg : null | ||
return <LoadingOrErrorPage loading={loading} error={errorToPrint}/> | ||
} | ||
|
||
if (isAccessLoading) { | ||
return <LoadingOrErrorPage error='' loading={true}/> | ||
} | ||
|
||
if (!canManage) { | ||
return <AccessDeniedPage/> | ||
} | ||
|
||
return <CreateNewsPageContent /> | ||
return <CreateNewsPageContent propertiesCount={propertiesCount} canManage={canManage} /> | ||
} | ||
|
||
CreateNewsPage.requiredAccess = NewsReadAndManagePermissionRequired | ||
|
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ import { useNewsItemsAccess } from '@condo/domains/news/hooks/useNewsItemsAccess | |
import { useTableColumns } from '@condo/domains/news/hooks/useTableColumns' | ||
import { useTableFilters } from '@condo/domains/news/hooks/useTableFilters' | ||
import { NewsItem } from '@condo/domains/news/utils/clientSchema' | ||
import { Property } from '@condo/domains/property/utils/clientSchema' | ||
import { IFilters } from '@condo/domains/ticket/utils/helpers' | ||
|
||
|
||
|
@@ -127,6 +128,9 @@ const NewsPageContent = ({ | |
const SearchPlaceholder = intl.formatMessage({ id: 'filters.FullSearch' }) | ||
const EmptyListLabel = intl.formatMessage({ id: 'pages.condo.news.index.emptyList.header' }) | ||
const EmptyListMessage = intl.formatMessage({ id: 'pages.condo.news.index.emptyList.title' }) | ||
const PropertyGateLabel = intl.formatMessage({ id: 'pages.condo.news.index.propertyGate.header' }) | ||
const PropertyGateMessage = intl.formatMessage({ id: 'pages.condo.news.index.propertyGate.title' }) | ||
const PropertyGateButtonLabel = intl.formatMessage({ id: 'pages.condo.property.index.CreatePropertyButtonLabel' }) | ||
const CreateNews = intl.formatMessage({ id: 'news.createNews' }) | ||
const ServerErrorMsg = intl.formatMessage({ id: 'ServerError' }) | ||
|
||
|
@@ -143,18 +147,41 @@ const NewsPageContent = ({ | |
[baseNewsQuery, filters, filtersToWhere]) | ||
const { canManage } = useNewsItemsAccess() | ||
|
||
const { organization } = useOrganization() | ||
|
||
const { | ||
count: propertiesCount, | ||
loading: propertiesLoading, | ||
error: propertiesError, | ||
} = Property.useCount({ where: { organization: { id: get(organization, 'id') } }, first: 1 }) | ||
|
||
const { | ||
count: newsWithoutFiltersCount, | ||
loading: newsWithoutFiltersCountLoading, | ||
error, | ||
error: newsError, | ||
} = NewsItem.useCount({ where: baseNewsQuery }) | ||
const loading = newsWithoutFiltersCountLoading | ||
|
||
const loading = newsWithoutFiltersCountLoading || propertiesLoading | ||
const error = newsError || propertiesError | ||
|
||
if (loading || error) { | ||
const errorToPrint = error ? ServerErrorMsg : null | ||
return <LoadingOrErrorPage loading={loading} error={errorToPrint}/> | ||
} | ||
|
||
if (propertiesCount === 0 && newsWithoutFiltersCount === 0) { | ||
return ( | ||
<EmptyListContent | ||
image='/dino/[email protected]' | ||
label={PropertyGateLabel} | ||
message={PropertyGateMessage} | ||
createRoute='/property/create?next=/news&skipTourModal=true' | ||
createLabel={PropertyGateButtonLabel} | ||
accessCheck={canManage} | ||
/> | ||
) | ||
} | ||
|
||
if (newsWithoutFiltersCount === 0) { | ||
return ( | ||
<EmptyListContent | ||
|
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