-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ec6212
commit bb39e33
Showing
10 changed files
with
225 additions
and
10 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
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'; |
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 |
---|---|---|
@@ -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'; |
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,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." | ||
} | ||
} | ||
|
||
} |
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