Skip to content

Commit

Permalink
[DEV-1347]: change subscribe button click logic (#708)
Browse files Browse the repository at this point in the history
* feat(DEV-1437): change subscribe button click logic

* chore: add changeset

* feat(DEV-1437): use router.push instead of router.replace

* feat(DEV-1347): refact code to subscribe after user login

* chore: update changeset

Co-authored-by: marcobottaro <[email protected]>

* feat(DEV-1347): refact code to subscribe after user login

* [DEV-1433]: display hero from Strapi (#672)

* feat(DEV-1433): display hero from Strapi

* feat(DEV-1433): update test

* chore: add changeset

* feat(DEV-1433): update test

* feat(DEV-1433): update code

* feat(DEV-1433): update codecs names

* feat(DEV-1433): fix codec bugs

* feat(DEV-1433): add test

* feat(DEV-1433): fix tests

* chore: remove console.log

Co-authored-by: AF <[email protected]>

* feat(DEV-1433): simplify logic

Co-authored-by: AF <[email protected]>

* [DEV-1342] Remove email in url (#663)

* Remove email in url

* eslint

* changeset

* pr comment

---------

Co-authored-by: marcobottaro <[email protected]>

* Do not fetch from cache when executing deploy website workflow (#699)

* Update CHANGELOG and prepare next release (#682)

* Fix pagoPA guides and manuals version (#700)

* Revert "Fix pagoPA guides and manuals version (#700)" (#701)

This reverts commit 17ef179.

* [DPC-160] Fix pagoPA guides and manuals version (#702)

* Update CHANGELOG and prepare next release (#703)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* chore: fix typo

* Add NullToUndefined custom type

* feat(DEV-1433): simplify logic

Co-authored-by: AF <[email protected]>

* feat(DEV-1433): add explanatory comment

---------

Co-authored-by: AF <[email protected]>
Co-authored-by: marcobottaro <[email protected]>
Co-authored-by: tommaso1 <[email protected]>
Co-authored-by: Marco Comi <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Marco Ponchia <[email protected]>
Co-authored-by: Marco Bottaro <[email protected]>

* [DEV-1427] Move infrastructure under the monorepo structure (#720)

* [DEV-1465] Reset login form errors on user changes (#692)

* refactor login form

* handle reset errors on change input value

* add LoginForm tests

* add test

* Create sour-penguins-smile.md

* Moved test file

* fix error prop value

* improve test

* pr changes

* minor fixes

* changes after review

* Update .changeset/sour-penguins-smile.md

Co-authored-by: marcobottaro <[email protected]>

---------

Co-authored-by: marcobottaro <[email protected]>

* [DPC-175] Removes ref. to specific versions in the guide list and redirects to the latest pagoPA (#726)

* [DPC-175] Removes all ref to specific versions in the guide list and redirects to the latest for pagoPA

* [DPC-175] Latest version in "pagoPA Panoramica"

* [DPC-175] Latest version in "pagoPA Quick Start"

---------

Co-authored-by: marcobottaro <[email protected]>

* [DPC-171] Removes ref. to specific version and redirects to lates in Quick Start  Firma con IO (#727)

Co-authored-by: marcobottaro <[email protected]>

* [DEV-1503] Add googleusercontent to trusted domains (#722)

* Revert "[DPC-171] Removes ref. to specific version and redirects to lates in …" (#732)

* Revert "[DPC-175] Removes ref. to specific versions in the guide list and red…" (#731)

This reverts commit abdb055.

* [DPC-169] Removes version and redirects to latest in Panoramica App IO (#730)

* [DPC-169] Removes version and redirects to latest in Panoramica App IO

* [DPC-169]Removes version and redirects to latest in Webinar Description

* Add changeset

* [DPC-175] Removes ref. to specific versions in the guide list and redirects to the latest pagoPA  (#733)

* [DPC-175] Removes all ref to specific versions in the guide list and redirects to the latest for pagoPA

* [DPC-175] Latest version in "pagoPA Panoramica"

* [DPC-175] Latest version in "pagoPA Quick Start"

---------

Co-authored-by: Monica Costantini <[email protected]>

* [DPC-171] Removes specific version and redirects to lates in Quick Start Firma con IO (#734)

* [DPC-171] Removes ref. to specific version and redirects to lates in Quick Start  Firma con IO

* [DPC-175] Removes ref. to specific versions in the guide list and redirects to the latest pagoPA (#726)

* [DPC-175] Removes all ref to specific versions in the guide list and redirects to the latest for pagoPA

* [DPC-175] Latest version in "pagoPA Panoramica"

* [DPC-175] Latest version in "pagoPA Quick Start"

---------

Co-authored-by: marcobottaro <[email protected]>

---------

Co-authored-by: Monica Costantini <[email protected]>

* [DPC-170] Redirects to "Validatore" SEND latest version in HomePage (#728)

---------

Co-authored-by: marcobottaro <[email protected]>

* [DEV-1315]: highlight and hide webinars questions (#646)

* feat(DEV-1315): highlight and hide webinars questions

* feat(DEV-1315): add UpdateItem to host user

* chore: fix typo

* feat(DEV-1315): remove definitions from terraform

* chore: add changeset

* feat(DEV-1358): remove unused code

* feat(DEV-1315): update webinars questions' row

* feat(DEV-1315): update style

Co-authored-by: Marco Ponchia <[email protected]>

* feat(DEV-1315): update style

Co-authored-by: Marco Ponchia <[email protected]>

* feat(DEV-1315): update style

Co-authored-by: Marco Ponchia <[email protected]>

* chore: update changeset

Co-authored-by: marcobottaro <[email protected]>

* feat(DEV-1315): add user names

* chore: remove unused code

* feat(DEV-1315): update tests

* feat(DEV-1315): update code

* chore: remove unused code

* test: update tests

* feat(DEV-1315): update logic

* feat(DEV-1315): add default tcColor

* feat(DEV-1315): update IconButton visibility icon

Co-authored-by: Marco Ponchia <[email protected]>

* feat(DEV-1315): update WebinarQuestion codec to accept undefined values

* chore: remove test webinar

* feat(DEV-1315): unify update question logic

* chore: remove test webinar

* Webinar questions review (#704)

* feat(DEV-1315): update translation

Co-authored-by: marcobottaro <[email protected]>

---------

Co-authored-by: Marco Ponchia <[email protected]>
Co-authored-by: marcobottaro <[email protected]>
Co-authored-by: AF <[email protected]>
Co-authored-by: Marco Comi <[email protected]>

* [DEV-1448] Add concurrency in workflows that are using terraform (#735)

* [DEV-1448] Add concurrency group in deploy workflows (#737)

* [DPC-168]  Adds cover images for new BO manual for pagoPA (#739)

* [DEV-1505] Webinar tests (#729)

* Update CHANGELOG and prepare next release (#718)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Move working-directory to a single step (#740)

* Add changeset (#741)

* Update CHANGELOG and prepare next release (#742)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* feat(DEV-1347): redirect also the authenticated users

* feat(DEV-1347): update useEffect deps

---------

Co-authored-by: marcobottaro <[email protected]>
Co-authored-by: AF <[email protected]>
Co-authored-by: tommaso1 <[email protected]>
Co-authored-by: Marco Comi <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Marco Ponchia <[email protected]>
Co-authored-by: Marco Bottaro <[email protected]>
Co-authored-by: Jeremy Gordillo <[email protected]>
Co-authored-by: Monica Costantini <[email protected]>
  • Loading branch information
11 people authored Mar 15, 2024
1 parent 9bddc42 commit 24e856a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-vans-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nextjs-website": minor
---

Change webinars' subscribe button logic
2 changes: 1 addition & 1 deletion apps/nextjs-website/src/app/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Login = () => {
await Auth.sendCustomChallengeAnswer(user, code);

const redirect = searchParams.get('redirect');
router.replace(redirect ? redirect : '/');
router.replace(redirect ? atob(redirect) : '/');
},
[router, searchParams, user]
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import React, { useEffect } from 'react';
import React, { useCallback, useEffect } from 'react';
import { useState } from 'react';
import SubscribeButton from '../../atoms/SubscribeButton/SubscribeButton';
import {
Expand All @@ -9,7 +9,7 @@ import {
} from '@/helpers/userPreferences.helpers';
import { useTranslations } from 'next-intl';
import { DevPortalUser } from '@/lib/types/auth';
import { usePathname, useRouter } from 'next/navigation';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import { WebinarState } from '@/helpers/webinar.helpers';

export type SubscribeButtonProps = {
Expand Down Expand Up @@ -39,42 +39,44 @@ const SubscribeToWebinar = ({
const [isLoading, setIsLoading] = useState(false);
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
const action = searchParams.get('action');
const isSubscribeAction = action === 'subscribe';

useEffect(() => {
if (userAttributes && webinarSlug) {
setIsSubscribed(webinarSubscriptionExists(webinarSlug, userAttributes));
}
}, [userAttributes, webinarSlug]);
}, [setIsSubscribed, userAttributes, webinarSlug]);

if (!webinarSlug) {
return null;
}

const onUpdateAttributes = async (
generateNewAttributes: (
slug: string,
attributes: DevPortalUser['attributes']
) => DevPortalUser['attributes'] | Error,
errorMessage: string
): Promise<boolean> => {
if (!userAttributes || !setUserAttributes) {
handleErrorMessage && handleErrorMessage(t('genericSubscriptionError'));
return false;
}
const subscriptionResponse = generateNewAttributes(
webinarSlug,
userAttributes
);
if (subscriptionResponse instanceof Error) {
handleErrorMessage && handleErrorMessage(errorMessage);
return false;
} else {
await setUserAttributes(subscriptionResponse);
return true;
}
};
const onUpdateAttributes = useCallback(
async (
generateNewAttributes: (
slug: string,
attributes: DevPortalUser['attributes']
) => DevPortalUser['attributes'] | Error,
errorMessage: string
): Promise<boolean> => {
if (!webinarSlug || !userAttributes || !setUserAttributes) {
handleErrorMessage && handleErrorMessage(t('genericSubscriptionError'));
return false;
}
const subscriptionResponse = generateNewAttributes(
webinarSlug,
userAttributes
);
if (subscriptionResponse instanceof Error) {
handleErrorMessage && handleErrorMessage(errorMessage);
return false;
} else {
await setUserAttributes(subscriptionResponse);
return true;
}
},
[handleErrorMessage, setUserAttributes, t, userAttributes, webinarSlug]
);

const onSubscribe = () => {
const onSubscribe = useCallback(() => {
setIsLoading(true);
onUpdateAttributes(
addWebinarSubscriptionToAttributes,
Expand All @@ -83,22 +85,23 @@ const SubscribeToWebinar = ({
if (updateSuccess) {
setIsSubscribed(true);
}
if (
webinarState === WebinarState.past ||
webinarState === WebinarState.live
) {
if (!pathname.includes(`/webinars/${webinarSlug}`)) {
// eslint-disable-next-line functional/immutable-data
router.push(`/webinars/${webinarSlug}`);
}
setIsLoading(false);
});
return null;
};
}, [onUpdateAttributes, pathname, router, setIsSubscribed, t, webinarSlug]);

const onSubscribeWithoutUser = () => {
setIsLoading(true);
const finalPath = !pathname.includes(`/webinars/${webinarSlug}`)
? `/webinars/${webinarSlug}?action=subscribe`
: `${pathname}?action=subscribe`;

// eslint-disable-next-line functional/immutable-data
router.push(`/auth/login?redirect=${pathname}`);
router.push(`/auth/login?redirect=${btoa(finalPath)}`);
return null;
};

Expand All @@ -116,6 +119,16 @@ const SubscribeToWebinar = ({
return null;
};

const onSubscribeClick = () =>
userAttributes ? onSubscribe() : onSubscribeWithoutUser();

useEffect(() => {
if (userAttributes && isSubscribeAction) {
onSubscribe();
router.replace(pathname);
}
}, [onSubscribe, pathname, router, isSubscribeAction, userAttributes]);

const subscribeLabelMap = {
[WebinarState.past]: 'view',
[WebinarState.comingSoon]: 'default',
Expand All @@ -124,6 +137,10 @@ const SubscribeToWebinar = ({
[WebinarState.unknown]: 'default',
};

if (!webinarSlug) {
return null;
}

if (
isSubscribed &&
(webinarState === WebinarState.live || webinarState === WebinarState.past)
Expand All @@ -133,10 +150,10 @@ const SubscribeToWebinar = ({

return (
<SubscribeButton
disabled={!userAligned || isLoading}
disabled={isSubscribeAction || !userAligned || isLoading}
isLoading={isLoading}
isSubscribed={isSubscribed}
onSubscribe={userAttributes ? onSubscribe : onSubscribeWithoutUser}
onSubscribe={onSubscribeClick}
onCancelSubscription={onUnsubscribe}
subscribeLabel={subscribeLabelMap[webinarState]}
/>
Expand Down

0 comments on commit 24e856a

Please sign in to comment.