From 147a47bfcb2eaa918d1c48135fd0186988de7b9d Mon Sep 17 00:00:00 2001 From: barshathakuri Date: Fri, 22 Nov 2024 14:32:17 +0545 Subject: [PATCH] Subscription page integration --- backend | 2 +- package.json | 2 +- src/components/Badge/index.tsx | 21 - src/components/Badge/styles.module.css | 6 - .../AlertInfo/AreaInfoDetail/index.tsx | 1 - src/views/AllSourcesFeeds/index.tsx | 1 - src/views/HistoricalAlerts/i18n.json | 2 + src/views/HistoricalAlerts/index.tsx | 124 +++--- src/views/HistoricalAlerts/styles.module.css | 6 + src/views/Home/AlertFilters/index.tsx | 19 - .../Sidebar/CountryAdmin1List/index.tsx | 9 +- src/views/Home/AlertsMap/index.tsx | 14 +- src/views/Home/AlertsTable/index.tsx | 21 +- src/views/Home/index.tsx | 93 ++-- src/views/Home/useAlertFilters.ts | 34 +- .../ActiveTableActions/index.tsx | 19 +- .../ArchiveTableActions/index.tsx | 15 +- .../AlertInfoItem/index.tsx | 2 +- .../SubscriptionDetail/i18n.json | 3 +- .../SubscriptionDetail/index.tsx | 256 ++++++++--- .../SubscriptionDetail/styles.module.css | 9 +- .../SubscriptionTableItem/i18n.json | 8 +- .../SubscriptionTableItem/index.tsx | 93 ++-- .../SubscriptionTableItem/styles.module.css | 9 +- src/views/MySubscription/common.tsx | 42 -- src/views/MySubscription/i18n.json | 8 +- src/views/MySubscription/index.tsx | 421 +++++++++++++++--- src/views/NewSubscriptionModal/i18n.json | 4 +- src/views/NewSubscriptionModal/index.tsx | 275 ++++++++---- yarn.lock | 14 +- 30 files changed, 1074 insertions(+), 459 deletions(-) delete mode 100644 src/components/Badge/index.tsx delete mode 100644 src/components/Badge/styles.module.css delete mode 100644 src/views/MySubscription/common.tsx diff --git a/backend b/backend index b83328d0..c02b63c4 160000 --- a/backend +++ b/backend @@ -1 +1 @@ -Subproject commit b83328d0dcb3c1d037b92af0e45b1c98e3d76248 +Subproject commit c02b63c4c220bae7de86b88a1627ecca7d00d8bd diff --git a/package.json b/package.json index 6b0f0406..ac4f2472 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@graphql-codegen/typescript-operations": "^4.2.0", "@hcaptcha/react-hcaptcha": "^1.11.0", "@ifrc-go/icons": "^1.3.3", - "@ifrc-go/ui": "^1.1.2", + "@ifrc-go/ui": "^1.2.1", "@mapbox/mapbox-gl-draw": "^1.4.3", "@placemarkio/geo-viewport": "^1.0.2", "@sentry/react": "^7.81.1", diff --git a/src/components/Badge/index.tsx b/src/components/Badge/index.tsx deleted file mode 100644 index 52ec6a8b..00000000 --- a/src/components/Badge/index.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { Container } from '@ifrc-go/ui'; - -import styles from './styles.module.css'; - -interface Props { - title: string; -} - -function Badge(props: Props) { - const { - title, - } = props; - - return ( - - {title} - - ); -} - -export default Badge; diff --git a/src/components/Badge/styles.module.css b/src/components/Badge/styles.module.css deleted file mode 100644 index 43bfb743..00000000 --- a/src/components/Badge/styles.module.css +++ /dev/null @@ -1,6 +0,0 @@ -.badge { - display: flex; - border-radius: 1em; - background-color: var(--go-ui-color-gray-20); - padding: var(--go-ui-spacing-2xs) var(--go-ui-spacing-sm); -} diff --git a/src/views/AlertDetails/AlertInfo/AreaInfoDetail/index.tsx b/src/views/AlertDetails/AlertInfo/AreaInfoDetail/index.tsx index 18e5e7be..b958d8f0 100644 --- a/src/views/AlertDetails/AlertInfo/AreaInfoDetail/index.tsx +++ b/src/views/AlertDetails/AlertInfo/AreaInfoDetail/index.tsx @@ -236,7 +236,6 @@ function AreaInfoDetail(props: Props) { onChange={setSelectedFeature} /> )} - withGridViewInFilter headingLevel={4} >
diff --git a/src/views/AllSourcesFeeds/index.tsx b/src/views/AllSourcesFeeds/index.tsx index f80cb43b..b10ca554 100644 --- a/src/views/AllSourcesFeeds/index.tsx +++ b/src/views/AllSourcesFeeds/index.tsx @@ -117,7 +117,6 @@ export function Component() { heading={strings.sourceFeedsTitle} > [numbe type Certainty = NonNullable[number]; type Category = NonNullable[number]; -type AlertType = NonNullable['alerts']>['items']>[number]; +type AlertType = NonNullable['historicalAlerts']>['items']>[number]; type Admin1 = AlertType['admin1s'][number]; const adminKeySelector = (admin1: AdminOption) => admin1.id; @@ -168,13 +166,18 @@ const categoryKeySelector = (category: Category) => category.key; const alertKeySelector = (item: AlertType) => item.id; const PAGE_SIZE = 20; -const ASC = 'ASC'; -const DESC = 'DESC'; + +type NewFilter = Omit & AlertFilter['infos'] & { + startDateAfter?: string; + startDateBefore?: string; +}; // eslint-disable-next-line import/prefer-default-export export function Component() { const strings = useTranslation(i18n); + const [finalFilter, setFinalFilter] = useState(); + const { sortState, limit, @@ -185,55 +188,62 @@ export function Component() { setFilterField, filtered, offset, - } = useFilterState({ + setFilter, + } = useFilterState({ pageSize: PAGE_SIZE, filter: {}, }); - const order = useMemo(() => { - if (isNotDefined(sortState.sorting)) { - return undefined; - } - return { - [sortState.sorting.name]: sortState.sorting.direction === 'asc' ? ASC : DESC, - }; - }, [sortState.sorting]); - - const variables = useMemo<{ filters: AlertFilter, pagination: OffsetPaginationInput }>(() => ({ + const variables = useMemo<{ + filters: AlertFilter | undefined, + pagination: OffsetPaginationInput, + }>(() => ({ pagination: { offset, limit, }, - order, - filters: { - urgency: filter.urgency, - severity: filter.severity, - certainty: filter.certainty, - category: filter.category, - country: isDefined(filter.country?.pk) ? { pk: filter.country.pk } : undefined, - admin1: filter.admin1, - sent: isDefined(filter.sent) ? { - // TODO: Add start date & end date + filters: finalFilter ? { + DISTINCT: true, + infos: { + urgency: finalFilter?.urgency, + severity: finalFilter?.severity, + certainty: finalFilter?.certainty, + category: finalFilter?.category, + }, + country: isDefined(finalFilter?.country?.pk) + ? { pk: finalFilter.country.pk } : undefined, + admin1: finalFilter?.admin1, + sent: { range: { - end: filter.sent, - start: filter.sent, + end: finalFilter?.startDateBefore, + start: finalFilter?.startDateAfter, }, - } : undefined, - }, + }, + } : undefined, }), [ - order, limit, offset, - filter, + finalFilter, ]); + const handleApplyFilters = useCallback(() => { + setFinalFilter(rawFilter); + }, [ + rawFilter, + ]); + + const handleResetFilters = useCallback(() => { + setFinalFilter(undefined); + setFilter({}); + }, [setFilter]); + const { loading: alertInfoLoading, previousData, data: alertInfosResponse = previousData, error: alertInfoError, - } = useQuery( - ALERT_INFORMATIONS, + } = useQuery( + HISTORICAL_ALERT_INFORMATIONS, { skip: isNotDefined(variables), variables, @@ -280,7 +290,7 @@ export function Component() { { variables: adminQueryVariables, skip: isNotDefined(filter.country) }, ); - const data = alertInfosResponse?.public.alerts; + const data = alertInfosResponse?.public.historicalAlerts; const columns = useMemo( () => ([ @@ -374,7 +384,6 @@ export function Component() { className={styles.alertsTable} heading={heading} withHeaderBorder - withGridViewInFilter actions={( - {/* // TODO Add start date and end date filter */} { }} + value={rawFilter.startDateAfter} + onChange={setFilterField} /> { }} + value={rawFilter.startDateBefore} + onChange={setFilterField} /> +
+ + +
)} > diff --git a/src/views/HistoricalAlerts/styles.module.css b/src/views/HistoricalAlerts/styles.module.css index 2b1da9d6..15dc359b 100644 --- a/src/views/HistoricalAlerts/styles.module.css +++ b/src/views/HistoricalAlerts/styles.module.css @@ -64,5 +64,11 @@ text-decoration: underline; color: var(--go-ui-color-primary-red); } + + .filter-button { + display: flex; + gap: var(--go-ui-spacing-md); + align-items: flex-end; + } } } \ No newline at end of file diff --git a/src/views/Home/AlertFilters/index.tsx b/src/views/Home/AlertFilters/index.tsx index ac32b497..b8c270ee 100644 --- a/src/views/Home/AlertFilters/index.tsx +++ b/src/views/Home/AlertFilters/index.tsx @@ -131,16 +131,12 @@ function AlertFilters(props: Props) { selectedUrgencyTypes, selectedCertaintyTypes, activeRegionId, - // startDateFrom, - // startDateTo, setActiveCountryId, setActiveAdmin1Id, setSelectedSeverityTypes, setSelectedUrgencyTypes, setSelectedCertaintyTypes, setActiveRegionId, - // setStartDateFrom, - // setStartDateTo, selectedCategoryTypes, setSelectedCategoryTypes, } = useContext(AlertDataContext); @@ -231,21 +227,6 @@ function AlertFilters(props: Props) { value={selectedCertaintyTypes} onChange={setSelectedCertaintyTypes} /> - {/* - Add these filter after adding Historical alerts - - - */} {variant === 'table' && ( ({ countryId, alertFilters: { - severity: alertFilters.severity, - certainty: alertFilters.certainty, - urgency: alertFilters.urgency, + DISTINCT: true, + infos: { + severity: alertFilters.infos?.severity, + certainty: alertFilters.infos?.certainty, + urgency: alertFilters.infos?.urgency, + }, sent: alertFilters.sent, }, }), diff --git a/src/views/Home/AlertsMap/index.tsx b/src/views/Home/AlertsMap/index.tsx index 24bdabbe..e3a74d13 100644 --- a/src/views/Home/AlertsMap/index.tsx +++ b/src/views/Home/AlertsMap/index.tsx @@ -188,14 +188,11 @@ export function Component() { ); const defaultSubscription = useMemo(() => ({ - name: '', - alertFilters: { - urgency: selectedUrgencyTypes, - severity: selectedSeverityTypes, - certainty: selectedCertaintyTypes, - country: activeCountryId ?? '', - admin1s: activeAdmin1Id ? [activeAdmin1Id] : [], - }, + filterAlertUrgencies: selectedUrgencyTypes, + filterAlertCertainties: selectedCertaintyTypes, + filterAlertSeverities: selectedSeverityTypes, + filterAlertCountry: activeCountryId || '', + filterAlertAdmin1s: activeAdmin1Id ? [activeAdmin1Id] : [], }), [ selectedUrgencyTypes, selectedSeverityTypes, @@ -251,7 +248,6 @@ export function Component() { contentViewType="grid" numPreferredGridContentColumns={3} filters={} - withGridViewInFilter > {showSubscriptionModal && ( { setFilter({ ...alertFilters, + DISTINCT: true, country: isDefined(activeCountryId) ? { pk: activeCountryId } : undefined, admin1: activeAdmin1Id, region: activeRegionId, - category: selectedCategoryTypes, + infos: { + category: selectedCategoryTypes, + }, sent: isDefined(startDateFrom) && isDefined(startDateTo) ? { range: { end: startDateTo, @@ -288,20 +291,21 @@ export function Component() { ); const defaultSubscription = useMemo(() => ({ + id: '', name: '', - alertFilters: { - urgency: selectedUrgencyTypes, - severity: selectedSeverityTypes, - certainty: selectedCertaintyTypes, - country: activeCountryId ?? '', - admin1s: activeAdmin1Id ? [activeAdmin1Id] : [], - }, + filterAlertUrgencies: selectedUrgencyTypes, + filterAlertCertainties: selectedCertaintyTypes, + filterAlertSeverities: selectedSeverityTypes, + filterAlertCategories: selectedCategoryTypes, + filterAlertCountry: activeCountryId || '', + filterAlertAdmin1s: activeAdmin1Id ? [activeAdmin1Id] : [], }), [ selectedUrgencyTypes, selectedSeverityTypes, selectedCertaintyTypes, activeCountryId, activeAdmin1Id, + selectedCategoryTypes, ]); return ( @@ -317,7 +321,6 @@ export function Component() {
)} withHeaderBorder - withGridViewInFilter actions={(
diff --git a/yarn.lock b/yarn.lock index 44d5ccf0..943b34a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1699,12 +1699,18 @@ resolved "https://registry.yarnpkg.com/@ifrc-go/icons/-/icons-1.3.3.tgz#6a4aaf8a06ba237d2de269e84a1561f0a395deb1" integrity sha512-43sLUn0jH3v+gkJC0bT6oYWlsPg9isAT/x/qYhmZHb53iQOlWjUC9fNNSQq3nzklH7+mvHhXFXBbotSeFEtLhw== -"@ifrc-go/ui@^1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@ifrc-go/ui/-/ui-1.1.2.tgz#ece85236abb661ad5cb4cd5e99ec63525feda9c8" - integrity sha512-BiKNoe72xrNkDSqf14dsu3w8f4h20Q2C91VWAX1ZWV64pGf6exZwxMGPQm6RPL299R6m47eTwHQndyQZJCjXoQ== +"@ifrc-go/icons@^2.0.1": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@ifrc-go/icons/-/icons-2.0.1.tgz#7b8fe49ceed3e51de182bd97bcdbc6c9e9914351" + integrity sha512-j0KXz5UgUgVBfSljx6XATBWchj1tDckaGX+uI86QTO63teP5zCd6osR9q/e6H3jv8bzil1sdUmVt4VOwSX6xhw== + +"@ifrc-go/ui@^1.2.1": + version "1.2.1" + resolved "https://registry.yarnpkg.com/@ifrc-go/ui/-/ui-1.2.1.tgz#12f611a2200cbf00f3e82c0a10cf5aa79d75dd28" + integrity sha512-ZdWffxnowjtY8wgIuheS4mf3P1JnoKKaEC8yrf0JHceb3fCenMXJqMBQEdRMaJNBtd4MhQhuls53uErzX/l2gA== dependencies: "@changesets/cli" "^2.27.1" + "@ifrc-go/icons" "^2.0.1" "@togglecorp/fujs" "^2.1.1" react-focus-on "^3.9.1" sanitize-html "^2.11.0"