feat: list noti

:%s
This commit is contained in:
lytrankieio123
2021-10-22 17:33:43 +07:00
parent 388a6e0c22
commit 3d8070de04
8 changed files with 186 additions and 64 deletions

View File

@@ -105,6 +105,16 @@ export type QuerySearchArgs = {
input: SearchInput input: SearchInput
} }
export type QueryNewNotificationsArgs = {
customOption?: Maybe<CustomNotificationListOptions>;
options?: Maybe<NotificationListOptions>;
};
export type QueryNotificationsArgs = {
customOption?: Maybe<CustomNotificationListOptions>;
options?: Maybe<NotificationListOptions>;
};
export type Mutation = { export type Mutation = {
__typename?: 'Mutation' __typename?: 'Mutation'
/** Adds an item to the order. If custom fields are defined on the OrderLine entity, a third argument 'customFields' will be available. */ /** Adds an item to the order. If custom fields are defined on the OrderLine entity, a third argument 'customFields' will be available. */
@@ -2855,6 +2865,51 @@ export type FacetListOptions = {
filter?: Maybe<FacetFilterParameter> filter?: Maybe<FacetFilterParameter>
} }
export type CustomNotificationListOptions = {
skip?: Maybe<Scalars['Int']>;
take?: Maybe<Scalars['Int']>;
};
export type Notification = Node & {
__typename?: 'Notification';
createdAt: Scalars['DateTime'];
data: Scalars['JSON'];
description: Scalars['String'];
id: Scalars['ID'];
isNew: Scalars['Boolean'];
order?: Maybe<Order>;
type: HistoryEntryType;
updatedAt: Scalars['DateTime'];
};
export type NotificationFilterParameter = {
createdAt?: Maybe<DateOperators>;
description?: Maybe<StringOperators>;
isNew?: Maybe<BooleanOperators>;
type?: Maybe<StringOperators>;
updatedAt?: Maybe<DateOperators>;
};
export type NotificationList = PaginatedList & {
__typename?: 'NotificationList';
items: Array<Notification>;
totalItems: Scalars['Int'];
};
export type NotificationListOptions = {
filter?: Maybe<NotificationFilterParameter>;
skip?: Maybe<Scalars['Int']>;
sort?: Maybe<NotificationSortParameter>;
take?: Maybe<Scalars['Int']>;
};
export type NotificationSortParameter = {
createdAt?: Maybe<SortOrder>;
description?: Maybe<SortOrder>;
id?: Maybe<SortOrder>;
updatedAt?: Maybe<SortOrder>;
};
export type UpdateOrderItemsResult = export type UpdateOrderItemsResult =
| Order | Order
| OrderModificationError | OrderModificationError
@@ -3501,6 +3556,30 @@ export type ActiveOrderQuery = { __typename?: 'Query' } & {
activeOrder?: Maybe<{ __typename?: 'Order' } & CartFragment> activeOrder?: Maybe<{ __typename?: 'Order' } & CartFragment>
} }
export type NewNotificationsQuery = { __typename?: 'Query' } & {
newNotifications?: { __typename?: 'NotificationList' } & {
items: Array<
{ __typename?: 'Notification' } & Pick<
Notification,
'id' | 'createdAt' | 'createdAt' | 'type' | 'data' | 'order'
>
>,
'totalItems'
}
}
export type NotificationsQuery = { __typename?: 'Query' } & {
notifications?: { __typename?: 'NotificationList' } & {
items: Array<
{ __typename?: 'Notification' } & Pick<
Notification,
'id' | 'createdAt' | 'updatedAt' | 'type' | 'data' | 'description' |'order' |'isNew'
>
>,
'totalItems'
}
}
export type GetCollectionsQueryVariables = Exact<{ [key: string]: never }> export type GetCollectionsQueryVariables = Exact<{ [key: string]: never }>
export type GetCollectionsQuery = { __typename?: 'Query' } & { export type GetCollectionsQuery = { __typename?: 'Query' } & {

View File

@@ -0,0 +1,45 @@
export const newNotificationsQuery = /* GraphQL */ `
query newNotifications($customOption: CustomNotificationListOptions) {
newNotifications(customOption: $customOption) {
totalItems
items {
id
createdAt
type
data
description
isNew
order {
id
code
customFields {
lastedNotificationAt
}
}
}
}
}
`
export const notificationsQuery = /* GraphQL */ `
query notifications($customOption: CustomNotificationListOptions) {
notifications(customOption: $customOption) {
totalItems
items {
id
createdAt
type
data
description
isNew
order {
id
code
customFields {
lastedNotificationAt
}
}
}
}
}
`

View File

@@ -0,0 +1,2 @@
export { default as useNotifications } from './useNotifications'

View File

@@ -0,0 +1,12 @@
import { NotificationsQuery, QueryNotificationsArgs } from '@framework/schema'
import { notificationsQuery } from '@framework/utils/queries/notification-query'
import gglFetcher from 'src/utils/gglFetcher'
import useSWR from 'swr'
const useNotifications = (options?: QueryNotificationsArgs) => {
const { data, isValidating, ...rest } = useSWR<NotificationsQuery>([notificationsQuery, options], gglFetcher)
console.log("data: ", data)
return { notifications: data?.notifications?.items, total: data?.notifications?.totalItems, loading: isValidating, ...rest }
}
export default useNotifications

View File

@@ -9,7 +9,6 @@
.contentWrapper { .contentWrapper {
padding-left: 1.6rem; padding-left: 1.6rem;
padding-bottom: 1.4rem; padding-bottom: 1.4rem;
max-width: 26.3rem;
.title { .title {
font-weight: bold; font-weight: bold;
color: var(--text-active); color: var(--text-active);

View File

@@ -1,29 +1,21 @@
import React, {useState} from 'react' import { Notification } from '@framework/schema'
import s from '../NotificationItem/NotificationItem.module.scss'
import ClassNames from 'classnames' import ClassNames from 'classnames'
import { IconBill } from 'src/components/icons'
import Link from 'next/link' import Link from 'next/link'
import {ROUTE , QUERY_KEY, ACCOUNT_TAB } from 'src/utils/constanst.utils' import React from 'react'
import { IconBill } from 'src/components/icons'
import { ACCOUNT_TAB, QUERY_KEY, ROUTE } from 'src/utils/constanst.utils'
import s from '../NotificationItem/NotificationItem.module.scss'
export interface NotificationItemProps extends Omit<Notification, "type" | "data"> {
export interface NotificationItemProps {
ID?: string,
title?: string,
content?: string,
date?: string,
checked?: boolean,
} }
const NotificationItem = ({ ID, title, content, date, checked}: NotificationItemProps) => { const NotificationItem = ({ description, createdAt, order, isNew }: NotificationItemProps) => {
const [isChecked, setChecked] = useState(checked)
const Check = () => {
setChecked(true)
}
return ( return (
<section className={ClassNames({ <section className={ClassNames({
[s.notificationItem] : true, [s.notificationItem]: true,
[s.isChecked] : isChecked, [s.isChecked]: !isNew,
})} })}
onClick = {Check}
> >
<div className={s.icon}> <div className={s.icon}>
<IconBill /> <IconBill />
@@ -32,13 +24,13 @@ const NotificationItem = ({ ID, title, content, date, checked}: NotificationItem
<a> <a>
<div className={s.contentWrapper}> <div className={s.contentWrapper}>
<div className={s.title}> <div className={s.title}>
{title} Order {order?.code}
</div> </div>
<div className={s.content}> <div className={s.content}>
{content} {description}
</div> </div>
<div className={s.date}> <div className={s.date}>
{date} {createdAt}
</div> </div>
</div> </div>
</a> </a>

View File

@@ -1,4 +1,5 @@
.notificationPage { .notificationPage {
min-height: 30rem;
padding-bottom: 5.4rem; padding-bottom: 5.4rem;
@screen md { @screen md {
padding-bottom: 12.8rem; padding-bottom: 12.8rem;

View File

@@ -1,56 +1,48 @@
import React from 'react' import React from 'react'
import LoadingCommon from 'src/components/common/LoadingCommon/LoadingCommon'
import { useNotifications } from 'src/components/hooks/notification'
import NotificationEmptyPage from '../NotificationEmptyPage/NotificationEmptyPage' import NotificationEmptyPage from '../NotificationEmptyPage/NotificationEmptyPage'
import NotificationItem, { NotificationItemProps } from '../NotificationItem/NotificationItem' import NotificationItem from '../NotificationItem/NotificationItem'
import s from './NotificationPage.module.scss' import s from './NotificationPage.module.scss'
interface NotificationPageProps { interface NotificationPageProps {
isEmpty?: boolean,
data?: NotificationItemProps[],
} }
const NOTIFICATION_DATA = [
{
ID: "ID33455", const NotificationPage = ({ }: NotificationPageProps) => {
title: "Your order ID33455", const { notifications, loading } = useNotifications()
content: "The order has been deliveried successfully!", if (loading) {
date: "2 days ago", return <div className={s.notificationPage}>
checked: false, <LoadingCommon />
}, </div>
{
ID: "ID33456",
title: "Your order ID33456",
content: "The order has been deliveried successfully!",
date: "2 days ago",
checked: false,
},
{
ID: "ID33457",
title: "Your order ID33457",
content: "The order has been deliveried successfully!",
date: "2 days ago",
checked: true,
} }
]
const NotificationPage = ({ isEmpty=false, data = NOTIFICATION_DATA }: NotificationPageProps) => {
return ( return (
<div className={s.notificationPage}> <div className={s.notificationPage}>
{
isEmpty ?
<NotificationEmptyPage />
:
<>
{ {
data.map(item => { !notifications || notifications.length === 0 ?
return ( <NotificationEmptyPage />
<NotificationItem key={`${item.ID}-${item.title}`} title={item.title} content={item.content} date={item.date} checked={item.checked}/> :
) <>
}) {
notifications.map(item => {
return (
<NotificationItem
key={item.id}
id={item.id}
description={item.description}
createdAt={item.createdAt}
updatedAt={item.updatedAt}
isNew={item.isNew}
order={item.order}
/>
)
})
}
</>
} }
</>
}
</div> </div>
) )
} }
export default NotificationPage export default NotificationPage