Skip to content

Commit

Permalink
Add subscription alert detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
barshathakuri committed Nov 19, 2024
1 parent 8785c25 commit 00a9601
Show file tree
Hide file tree
Showing 16 changed files with 307 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/App/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ const mySubscription = customWrapRoute({
},
});

const subscriptionDetail = customWrapRoute({
parent: rootLayout,
path: 'subscriptions/:subscriptionId',
component: {
render: () => import('#views/MySubscription/SubscriptionDetail'),
props: {},
},
context: {
title: 'Subscription Detail',
// TODO: Change visibility after login feature
visibility: 'anything',
},
});

const homeIndex = customWrapRoute({
parent: homeLayout,
index: true,
Expand Down Expand Up @@ -275,6 +289,7 @@ const wrappedRoutes = {
mySubscription,
cookiePolicy,
historicalAlerts,
subscriptionDetail,
};

export const unwrappedRoutes = unwrapRoute(Object.values(wrappedRoutes));
Expand Down
10 changes: 9 additions & 1 deletion src/views/MySubscription/ActiveTableActions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { MoreOptionsIcon } from '@ifrc-go/icons';
import {
DeleteBinSixLineIcon,
EditTwoLineIcon,
LayoutBottomLineIcon,
MoreOptionsIcon,
} from '@ifrc-go/icons';
import { DropdownMenu } from '@ifrc-go/ui';
import { useTranslation } from '@ifrc-go/ui/hooks';

Expand All @@ -19,19 +24,22 @@ function ActiveTableActions() {
type="button"
name="archive"
onClick={undefined}
icons={<LayoutBottomLineIcon />}
>
{strings.archiveSubscriptionActions}
</DropdownMenuItem>
<DropdownMenuItem
type="button"
name="edit"
icons={<EditTwoLineIcon />}
>
{strings.editSubscriptionActions}
</DropdownMenuItem>
<DropdownMenuItem
type="button"
name="delete"
onClick={undefined}
icons={<DeleteBinSixLineIcon />}
>
{strings.deleteSubscriptionActions}
</DropdownMenuItem>
Expand Down
8 changes: 7 additions & 1 deletion src/views/MySubscription/ArchiveTableActions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { MoreOptionsIcon } from '@ifrc-go/icons';
import {
DeleteBinSixLineIcon,
LayoutBottomLineIcon,
MoreOptionsIcon,
} from '@ifrc-go/icons';
import { DropdownMenu } from '@ifrc-go/ui';
import { useTranslation } from '@ifrc-go/ui/hooks';

Expand All @@ -18,13 +22,15 @@ function ArchiveTableActions() {
<DropdownMenuItem
type="button"
name="unArchive"
icons={<LayoutBottomLineIcon />}
>
{strings.unarchiveSubscriptionActions}
</DropdownMenuItem>
<DropdownMenuItem
type="button"
name="delete"
onClick={undefined}
icons={<DeleteBinSixLineIcon />}
>
{strings.deleteSubscriptionActions}
</DropdownMenuItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"namespace": "alertInfo",
"strings": {
"alertInfoView": "View"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Container } from '@ifrc-go/ui';
import { useTranslation } from '@ifrc-go/ui/hooks';

import Link from '#components/Link';

import i18n from './i18n.json';
import styles from './styles.module.css';

interface Props {
alertId: string;
alertTitle: string;
alertDescription?: string;
}

function AlertInfoItem(props: Props) {
const strings = useTranslation(i18n);

const {
alertId,
alertTitle,
alertDescription,
} = props;

return (
<Container
className={styles.alertDetail}
heading={alertTitle}
headingLevel={4}
actions={(
<Link
to="alertDetails"
urlParams={{ alertId }}
variant="secondary"
>
{strings.alertInfoView}
</Link>
)}
footerContent={alertDescription}
/>
);
}

export default AlertInfoItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.alert-detail {
background-color: var(--go-ui-color-gray-20);
padding: var(--go-ui-spacing-md);
}
9 changes: 9 additions & 0 deletions src/views/MySubscription/SubscriptionDetail/i18n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"namespace": "subscriptionDetail",
"strings": {
"subscriptionDetailTitle": "Subscription Detail",
"subscriptionHeading": "Subscription",
"filterStartDateFrom": "Start date from",
"filterStartDateTo": "Start date To"
}
}
131 changes: 131 additions & 0 deletions src/views/MySubscription/SubscriptionDetail/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { useCallback } from 'react';
import {
Container,
DateInput,
List,
} from '@ifrc-go/ui';
import { useTranslation } from '@ifrc-go/ui/hooks';

import Page from '#components/Page';
import { stringIdSelector } from '#utils/selectors';

import {
AlertInfo,
SubscriptionAndAlertDetail,
} from '../common';
import AlertInfoItem from './AlertInfoItem';

import i18n from './i18n.json';
import styles from './styles.module.css';

// eslint-disable-next-line import/prefer-default-export
export function Component() {
const strings = useTranslation(i18n);

const subscriptionAndAlertDetail: SubscriptionAndAlertDetail[] = [
{
id: '1',
alertFilter: ['Future', 'Severe', 'Nepal'],
alertInfo: [
{
id: '1',
alertId: '101',
alertTitle: 'Flood Alert',
alertDescription: 'Severe flooding expected in the coastal region.',
},
{
id: '2',
alertId: '102',
alertTitle: 'Heatwave Warning',
alertDescription: 'Extreme heatwave affecting northern regions.',
},
{
id: '3',
alertId: '103',
alertTitle: 'Earthquake Advisory',
alertDescription: 'Possible aftershocks in the affected areas.',
},
],
},
];

const alertInfo: AlertInfo[] = [
{
id: '1',
alertId: '101',
alertTitle: 'Flood Alert',
alertDescription: 'Severe flooding expected in the coastal region.',
},
{
id: '2',
alertId: '102',
alertTitle: 'Heatwave Warning',
alertDescription: 'Extreme heatwave affecting northern regions.',
},
{
id: '3',
alertId: '103',
alertTitle: 'Earthquake Advisory',
alertDescription: 'Possible aftershocks in the affected areas.',
},
];

const rendererParams = useCallback((_: string, value: AlertInfo) => ({
alertId: value.alertId,
alertTitle: value.alertTitle,
alertDescription: value?.alertDescription,
}), []);

return (
<Page
className={styles.subscriptionDetail}
title={strings.subscriptionDetailTitle}
// TODO: Add subscription heading and description
heading={strings.subscriptionHeading}
>
<Container
childrenContainerClassName={styles.alertFilters}
withGridViewInFilter
filters={(
<>
<DateInput
name="startDateFrom"
label={strings.filterStartDateFrom}
value={undefined}
onChange={() => { }}
/>
<DateInput
name="startDateTo"
label={strings.filterStartDateTo}
value={undefined}
onChange={() => { }}
/>
</>
)}
>
<div className={styles.badgeContainer}>
{subscriptionAndAlertDetail?.map((filter) => (
<div
key={filter.id}
className={styles.badge}
>
{filter.alertFilter}
</div>
))}
</div>
<List
className={styles.alertItem}
data={alertInfo}
renderer={AlertInfoItem}
rendererParams={rendererParams}
keySelector={stringIdSelector}
pending={false}
errored={false}
filtered={false}
/>
</Container>
</Page>
);
}

Component.displayName = 'SubscriptionDetail';
25 changes: 25 additions & 0 deletions src/views/MySubscription/SubscriptionDetail/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.subscription-detail {
.alert-filters {
display: flex;
flex-direction: column;
gap: var(--go-ui-spacing-md);

.badge-container {
display: flex;
gap: var(--go-ui-spacing-md);

.badge {
border-radius: 1em;
background-color: var(--go-ui-color-gray-20);
padding: var(--go-ui-spacing-2xs) var(--go-ui-spacing-sm);
}
}

.alert-item {
display: flex;
flex-direction: column;
gap: var(--go-ui-spacing-md);
}
}

}
6 changes: 6 additions & 0 deletions src/views/MySubscription/SubscriptionTableItem/i18n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"namespace": "subscriptionItem",
"strings": {
"subscriptionItemView": "View"
}
}
30 changes: 25 additions & 5 deletions src/views/MySubscription/SubscriptionTableItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Container } from '@ifrc-go/ui';
import { useTranslation } from '@ifrc-go/ui/hooks';

import Link from '#components/Link';
import {
AlertInfoCertaintyEnum,
AlertInfoSeverityEnum,
AlertInfoUrgencyEnum,
} from '#generated/types/graphql';

import i18n from './i18n.json';
import styles from './styles.module.css';

interface Props {
id: string;
country: string | undefined;
admin1: string | undefined;
urgency?: AlertInfoUrgencyEnum[] | undefined;
Expand All @@ -21,6 +25,7 @@ interface Props {

function SubscriptionTableItem(props: Props) {
const {
id,
country,
admin1,
urgency,
Expand All @@ -31,8 +36,11 @@ function SubscriptionTableItem(props: Props) {
actions,
} = props;

const strings = useTranslation(i18n);

return (
<Container
key={id}
className={styles.subscriptionDetail}
heading={title}
headingLevel={4}
Expand All @@ -44,15 +52,27 @@ function SubscriptionTableItem(props: Props) {
{actions}
</>
)}
footerContentClassName={styles.alertDetail}
footerContent={(
<>
{country}
{admin1}
{urgency}
{certainty}
{severity}
<div>{country}</div>
<div>{admin1}</div>
<div>{urgency}</div>
<div>{certainty}</div>
<div>{severity}</div>
</>
)}
footerActions={(
<Link
to="subscriptionDetail"
urlParams={{
subscriptionId: id,
}}
variant="secondary"
>
{strings.subscriptionItemView}
</Link>
)}
/>
);
}
Expand Down
Loading

0 comments on commit 00a9601

Please sign in to comment.