Skip to content

Commit

Permalink
Remove resources page summary
Browse files Browse the repository at this point in the history
  • Loading branch information
barshathakuri committed Dec 13, 2024
1 parent 3ec6212 commit bb39e33
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 10 deletions.
34 changes: 34 additions & 0 deletions src/App/redirects/AlertDetailsRedirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
generatePath,
useNavigate,
useParams,
} from 'react-router-dom';

import routes from '#routes';

interface AlertDetailsParams {
alertId: string | undefined;
[key: string]: string | undefined;
}

// eslint-disable-next-line import/prefer-default-export
export function Component() {
const { alertId } = useParams<AlertDetailsParams>();
const navigate = useNavigate();

const alertDetailsLink = (alertId) ? ({
pathname: (generatePath(
routes.alertDetails.absolutePath,
{ alertId },
)),
})
: routes.pageNotFound.path;

if (alertDetailsLink) {
navigate(alertDetailsLink);
}

return null;
}

Component.displayName = 'AlertDetailsRedirect';
136 changes: 136 additions & 0 deletions src/App/redirects/UnsubscribeRedirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import {
useCallback,
useEffect,
} from 'react';
import {
generatePath,
useNavigate,
useParams,
} from 'react-router-dom';
import {
gql,
useMutation,
useQuery,
} from '@apollo/client';

import {
AlertSubscriptionsUnsubscribeQuery,
AlertSubscriptionsUnsubscribeQueryVariables,
UnsubscriptionMutation,
UnsubscriptionMutationVariables,
} from '#generated/types/graphql';
import routes from '#routes';

const ALERT_SUBSCRIPTIONS = gql`
query AlertSubscriptionsUnsubscribe {
private {
id
userAlertSubscriptions {
items {
id
name
isActive
filterAlertAdmin1s
filterAlertCountryId
}
}
}
}
`;

const UPDATE_SUBSCRIPTION = gql`
mutation Unsubscription(
$subscriptionId: ID!,
$data: UserAlertSubscriptionInput!,
) {
private {
updateUserAlertSubscription(
id: $subscriptionId,
data: $data,
) {
errors
ok
result {
id
name
isActive
}
}
}
}
`;

interface UnsubscribeParams {
subscriptionId: string | undefined;
token: string | undefined;
[key: string]: string | undefined;
}

// eslint-disable-next-line import/prefer-default-export
export function Component() {
const { subscriptionId, token } = useParams<UnsubscribeParams>();
const navigate = useNavigate();

const {
data: alertSubscriptions,
} = useQuery<
AlertSubscriptionsUnsubscribeQuery,
AlertSubscriptionsUnsubscribeQueryVariables
>(
ALERT_SUBSCRIPTIONS,
);

const [
triggerSubscriptionUpdate,
] = useMutation<
UnsubscriptionMutation,
UnsubscriptionMutationVariables
>(
UPDATE_SUBSCRIPTION,
);

const data = alertSubscriptions?.private?.userAlertSubscriptions?.items;

const handleUnsubscribe = useCallback((id: string) => {
const selectedSubscriptionDetails = data?.find(
(sub) => sub.id === id,
);

triggerSubscriptionUpdate({
variables: {
subscriptionId: id,
data: {
isActive: false,
filterAlertAdmin1s: selectedSubscriptionDetails?.filterAlertAdmin1s ?? [],
filterAlertCountry: selectedSubscriptionDetails?.filterAlertCountryId ?? '',
name: selectedSubscriptionDetails?.name ?? '',
},
},
});
}, [
data,
triggerSubscriptionUpdate,
]);

useEffect(() => {
if (subscriptionId) {
handleUnsubscribe(subscriptionId);
}
}, [
handleUnsubscribe,
subscriptionId,
]);

const UnsubscribeLink = (subscriptionId && token) ? ({
pathname: (generatePath(routes.subscriptionDetail.absolutePath, { subscriptionId, token })),
})
: routes.pageNotFound.path;

if (UnsubscribeLink) {
navigate(UnsubscribeLink);
}

return null;
}

Component.displayName = 'UnsubscribeRedirect';
31 changes: 31 additions & 0 deletions src/App/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ const alertDetails = customWrapRoute({
},
});

const alertDetailRedirect = customWrapRoute({
parent: rootLayout,
path: 'permalink/alert-details/:alertId',
component: {
render: () => import('../redirects/AlertDetailsRedirect.tsx'),
props: {},
},
wrapperComponent: Auth,
context: {
title: 'Alert Details',
visibility: 'anything',
},
});

const allSourcesFeeds = customWrapRoute({
parent: rootLayout,
path: 'feeds',
Expand Down Expand Up @@ -311,6 +325,7 @@ const resetPasswordRedirect = customWrapRoute({
visibility: 'is-not-authenticated',
},
});

const activation = customWrapRoute({
parent: rootLayout,
path: 'activation/:userId/:token',
Expand Down Expand Up @@ -339,6 +354,20 @@ const activationRedirect = customWrapRoute({
},
});

const unSubscribeRedirect = customWrapRoute({
parent: rootLayout,
path: 'permalink/unsubscribe-user-alert-subscription/:subscriptionsId',
component: {
render: () => import('../redirects/UnsubscribeRedirect.tsx'),
props: {},
},
wrapperComponent: Auth,
context: {
title: 'Unsubscribe Redirect',
visibility: 'anything',
},
});

const wrappedRoutes = {
rootLayout,
homeLayout,
Expand All @@ -363,6 +392,8 @@ const wrappedRoutes = {
resetPasswordRedirect,
activationRedirect,
activation,
alertDetailRedirect,
unSubscribeRedirect,
};

export const unwrappedRoutes = unwrapRoute(Object.values(wrappedRoutes));
Expand Down
9 changes: 4 additions & 5 deletions src/views/Activation/i18n.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"namespace": "activation",
"strings": {
"activationSuccessMessage":"Your account has been successfully activated!",
"goToLogin":"Go to Login",
"activationFailMessage":"An error occurred during activation. Please try again."
"activationSuccessMessage": "Your account has been successfully activated!",
"goToLogin": "Go to Login",
"activationFailMessage": "This account has already been activated."
}
}

}
2 changes: 1 addition & 1 deletion src/views/Home/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"addSubscriptionDescription": "With real-time monitoring of potential risks and emergency events, receive timely and accurate alerts.",
"useApi": "Use API to rebroadcast CAP alerts",
"useApiDescription": "With simple yet powerful API endpoints, you can tailor the alerts to suit your users' needs.",
"alertNewSubscription": "Subscribe Alerts ",
"alertNewSubscription": "Subscribe to Alerts ",
"alertApiReference": "API Reference"
}
}
11 changes: 10 additions & 1 deletion src/views/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
AlertFilter,
CountryDetailQuery,
} from '#generated/types/graphql';
import useAuth from '#hooks/domain/useAuth';
import useUrlSearchState from '#hooks/useUrlSearchState';
import NewSubscriptionModal from '#views/NewSubscriptionModal';

Expand Down Expand Up @@ -86,6 +87,7 @@ const filterKeys: CombinedAlertFilterKey[] = ['country', 'admin1', 'region', 'ur
// eslint-disable-next-line import/prefer-default-export
export function Component() {
const strings = useTranslation(i18n);
const { isAuthenticated } = useAuth();

const [
filters,
Expand Down Expand Up @@ -266,14 +268,21 @@ export function Component() {
heading={strings.addSubscription}
headerDescription={strings.addSubscriptionDescription}
withInternalPadding
footerContent={(
footerContent={isAuthenticated ? (
<Button
onClick={setShowSubscriptionModalTrue}
name={undefined}
variant="primary"
>
{strings.alertNewSubscription}
</Button>
) : (
<Link
variant="primary"
to="login"
>
{strings.alertNewSubscription}
</Link>
)}
/>
<Container
Expand Down
2 changes: 1 addition & 1 deletion src/views/RecoverAccount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export function Component() {
title={strings.successfulMessage}
/>
</Page>

);
}

Expand Down Expand Up @@ -183,6 +182,7 @@ export function Component() {
name="captcha"
onChange={setFieldValue}
onError={onCaptchaError}
error={fieldError?.captcha}
/>
<Button
name={undefined}
Expand Down
1 change: 1 addition & 0 deletions src/views/RecoverAccountConfirm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export function Component() {
name="captcha"
onChange={setFieldValue}
onError={onCaptchaError}
error={fieldError?.captcha}
/>
<Button
name={undefined}
Expand Down
6 changes: 6 additions & 0 deletions src/views/Register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ export function Component() {
errors,
));
setError(formError);
const errorMessages = errors
?.map((message: { messages: string; }) => message.messages)
.filter((message: string) => message)
.join(', ');
alert.show(errorMessages, { variant: 'danger' });
} else if (ok) {
navigate('/login');
alert.show(
Expand Down Expand Up @@ -267,6 +272,7 @@ export function Component() {
name="captcha"
onChange={setFieldValue}
onError={onCaptchaError}
error={error?.captcha}
/>
<Button
name={undefined}
Expand Down
3 changes: 1 addition & 2 deletions src/views/Resources/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function Component() {
{
id: 2,
title: strings.ifrcRelatedExternalLinksCapImplementation,
url: 'https://cap-workshop.alert-hub.org/2023/index.html',
url: 'https://cap-workshop.alert-hub.org/2024/index.html',
},
{
id: 3,
Expand All @@ -102,7 +102,6 @@ export function Component() {
mainSectionClassName={styles.resources}
title={strings.resourceAlerthubTitle}
heading={strings.resourceHeadingTitle}
description={strings.resourceHeadingDescription}
>
<Container
heading={strings.earlyWarningResourcesTitle}
Expand Down

0 comments on commit bb39e33

Please sign in to comment.