Skip to content

Commit

Permalink
fix: tackle pr comments and revert some incorrect changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mirovladimitrovski committed Sep 26, 2024
1 parent ec61a8f commit a3b6c71
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@use '@jwp/ott-ui-react/src/styles/variables';
@use '@jwp/ott-ui-react/src/styles/theme';

.topContainer {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 40px;
row-gap: 32px;

.circleHug {
display: flex;
justify-content: center;
align-items: center;
width: 80px;
height: 80px;
border: 2px solid variables.$green;
border-radius: 50%;
}
}

.innerContainer {
display: flex;
flex-direction: column;
align-items: center;
row-gap: 8px;

.title {
font-weight: var(--body-font-weight-bold);
font-size: 24px;
}

.message {
margin: 0;
font-size: 16px;
text-align: center;
}
}

.buttonContainer {
align-self: stretch;
}

.welcome {
h2 {
font-weight: var(--body-font-weight-bold);
font-size: 24px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import { act, fireEvent, render } from '@testing-library/react';

import PaymentSuccessful from './PaymentSuccessful';

describe('<PaymentSuccessful>', () => {
test('renders and matches snapshot', () => {
const { container } = render(<PaymentSuccessful siteName="Sitename!" />);

expect(container).toMatchSnapshot();
});

test('calls the onCloseButtonClick callback when clicking the close button', () => {
const onCloseButtonClick = vi.fn();
const { getByText } = render(<PaymentSuccessful onCloseButtonClick={onCloseButtonClick} siteName="Sitename!" />);

fireEvent.click(getByText('checkout.start_watching'));

expect(onCloseButtonClick).toBeCalled();
});

test('calls the onCloseButtonClick callback when clicking the close button', () => {
vi.useFakeTimers();
const onCountdownCompleted = vi.fn();

render(<PaymentSuccessful onCountdownCompleted={onCountdownCompleted} siteName="Sitename!" />);

let i = 10;
while (i--) {
act(() => {
vi.runAllTimers();
});
}

expect(onCountdownCompleted).toBeCalled();
vi.useRealTimers();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import CheckmarkSVG from '@jwp/ott-theme/assets/icons/check-green.svg?react';
import useCountdown from '@jwp/ott-hooks-react/src/useCountdown';

import Button from '../Button/Button';

import styles from './PaymentSuccessful.module.scss';

type Props = {
onCloseButtonClick?: () => void;
onCountdownCompleted?: () => void;
siteName?: string;
};

const PaymentSuccessful: React.FC<Props> = ({ onCloseButtonClick, onCountdownCompleted, siteName }) => {
const { t } = useTranslation('account');
const countdown = useCountdown(10, 1, onCountdownCompleted);

return (
<div className={styles.topContainer}>
<div className={styles.circleHug}>
<CheckmarkSVG />
</div>
<div className={styles.innerContainer}>
<h2 className={styles.title}>{t('checkout.payment_successful_title')}</h2>
<p className={styles.message}>{t('checkout.payment_successful_description', { siteName })}</p>
</div>
<div className={styles.buttonContainer}>
<Button label={t('checkout.start_watching', { countdown })} onClick={onCloseButtonClick} color="primary" variant="contained" size="large" fullWidth />
</div>
</div>
);
};

export default PaymentSuccessful;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`<PaymentSuccessful> > renders and matches snapshot 1`] = `
<div>
<div
class="_topContainer_4874d7"
>
<div
class="_circleHug_4874d7"
>
<svg
fill="none"
height="65"
viewBox="0 0 64 65"
width="64"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M13.3333 32.6663L26.6666 45.9997L53.3333 19.333"
stroke="#5aae4a"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="1.6"
/>
</svg>
</div>
<div
class="_innerContainer_4874d7"
>
<h2
class="_title_4874d7"
>
checkout.payment_successful_title
</h2>
<p
class="_message_4874d7"
>
checkout.payment_successful_description
</p>
</div>
<div
class="_buttonContainer_4874d7"
>
<button
class="_button_f8f296 _primary_f8f296 _fullWidth_f8f296 _large_f8f296"
type="button"
>
<span>
checkout.start_watching
</span>
</button>
</div>
</div>
</div>
`;
42 changes: 1 addition & 41 deletions packages/ui-react/src/components/Welcome/Welcome.module.scss
Original file line number Diff line number Diff line change
@@ -1,49 +1,9 @@
@use '@jwp/ott-ui-react/src/styles/variables';
@use '@jwp/ott-ui-react/src/styles/theme';

.topContainer {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 40px;
row-gap: 32px;

.circleHug {
display: flex;
justify-content: center;
align-items: center;
width: 80px;
height: 80px;
border: 2px solid variables.$green;
border-radius: 50%;
}
}

.innerContainer {
display: flex;
flex-direction: column;
align-items: center;
row-gap: 8px;

.title {
font-weight: var(--body-font-weight-bold);
font-size: 24px;
}

.message {
margin: 0;
font-size: 16px;
text-align: center;
}
}

.buttonContainer {
align-self: stretch;
}

.welcome {
h2 {
font-weight: var(--body-font-weight-bold);
font-size: 24px;
}
}
}
16 changes: 4 additions & 12 deletions packages/ui-react/src/components/Welcome/Welcome.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import CheckmarkSVG from '@jwp/ott-theme/assets/icons/check-green.svg?react';
import useCountdown from '@jwp/ott-hooks-react/src/useCountdown';

import Button from '../Button/Button';
Expand All @@ -18,17 +17,10 @@ const Welcome: React.FC<Props> = ({ onCloseButtonClick, onCountdownCompleted, si
const countdown = useCountdown(10, 1, onCountdownCompleted);

return (
<div className={styles.topContainer}>
<div className={styles.circleHug}>
<CheckmarkSVG />
</div>
<div className={styles.innerContainer}>
<h2 className={styles.title}>{t('checkout.welcome_title')}</h2>
<p className={styles.message}>{t('checkout.welcome_description', { siteName })}</p>
</div>
<div className={styles.buttonContainer}>
<Button label={t('checkout.start_watching', { countdown })} onClick={onCloseButtonClick} color="primary" variant="contained" size="large" fullWidth />
</div>
<div className={styles.welcome}>
<h2>{t('checkout.welcome_title', { siteName })}</h2>
<p>{t('checkout.welcome_description', { siteName })}</p>
<Button variant="contained" color="primary" label={t('checkout.start_watching', { countdown })} onClick={onCloseButtonClick} size="large" fullWidth />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,22 @@
exports[`<Welcome> > renders and matches snapshot 1`] = `
<div>
<div
class="_topContainer_c4a16f"
class="_welcome_c4a16f"
>
<div
class="_circleHug_c4a16f"
<h2>
checkout.welcome_title
</h2>
<p>
checkout.welcome_description
</p>
<button
class="_button_f8f296 _primary_f8f296 _fullWidth_f8f296 _large_f8f296"
type="button"
>
<svg
fill="none"
height="65"
viewBox="0 0 64 65"
width="64"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M13.3333 32.6663L26.6666 45.9997L53.3333 19.333"
stroke="#5aae4a"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="1.6"
/>
</svg>
</div>
<div
class="_innerContainer_c4a16f"
>
<h2
class="_title_c4a16f"
>
checkout.welcome_title
</h2>
<p
class="_message_c4a16f"
>
checkout.welcome_description
</p>
</div>
<div
class="_buttonContainer_c4a16f"
>
<button
class="_button_f8f296 _primary_f8f296 _fullWidth_f8f296 _large_f8f296"
type="button"
>
<span>
checkout.start_watching
</span>
</button>
</div>
<span>
checkout.start_watching
</span>
</button>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useQueryParam from '@jwp/ott-ui-react/src/hooks/useQueryParam';

import LoadingOverlay from '../../components/LoadingOverlay/LoadingOverlay';
import Welcome from '../../components/Welcome/Welcome';
import PaymentSuccessful from '../../components/PaymentSuccessful/PaymentSuccessful';
import PaymentFailed from '../../components/PaymentFailed/PaymentFailed';
import Dialog from '../../components/Dialog/Dialog';
import DeleteAccountModal from '../../components/DeleteAccountModal/DeleteAccountModal';
Expand Down Expand Up @@ -48,6 +49,7 @@ export type AccountModals = {
'payment-error': 'payment-error';
'payment-cancelled': 'payment-cancelled';
welcome: 'welcome';
'payment-successful': 'payment-successful';
'reset-password': 'reset-password';
'forgot-password': 'forgot-password';
'add-password': 'add-password';
Expand Down Expand Up @@ -134,6 +136,8 @@ const AccountModal = () => {
return <PaymentFailed type="cancelled" message={message} onCloseButtonClick={closeHandler} />;
case 'welcome':
return <Welcome onCloseButtonClick={closeHandler} onCountdownCompleted={closeHandler} siteName={siteName} />;
case 'payment-successful':
return <PaymentSuccessful onCloseButtonClick={closeHandler} siteName={siteName} />;
case 'reset-password':
return <ResetPassword type="reset" />;
case 'forgot-password':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ChooseOffer = () => {

const url = await chooseOffer.mutateAsync({
offer,
successUrl: `${baseUrl}${modalURLFromLocation(location, 'welcome')}`,
successUrl: `${baseUrl}${modalURLFromLocation(location, 'payment-successful')}`,
cancelUrl: `${baseUrl}${modalURLFromLocation(location, 'payment-cancelled')}`,
});

Expand Down
8 changes: 5 additions & 3 deletions platforms/web/public/locales/en/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"monthly": "Monthly subscription",
"no_payment_needed": "No payment needed",
"payment_cancelled": "Payment cancelled",
"payment_cancelled_message": "This payment attempt was cancelled and no charges were made. If this wasn’t intentional, please retry the payment process.",
"payment_cancelled_message": "You have cancelled the payment.",
"payment_error": "Payment failed",
"payment_method": "Payment method",
"payment_method_fee": "Payment method fee",
Expand All @@ -50,8 +50,10 @@
"upgrade_success": "Subscription updated!",
"upgrade_success_message": "Your subscription is updated and can be used immediately.",
"waiting_for_payment": "Waiting for payment",
"welcome_description": "Thank you for your subscription, enjoy all our content.",
"welcome_title": "Payment successful",
"welcome_description": "Thank you for subscribing to {{siteName}}. Please enjoy all our content.",
"welcome_title": "Welcome to {{siteName}}",
"payment_successful_title": "Payment successful",
"payment_successful_description": "Thank you for your subscription, enjoy all our content.",
"yearly": "Yearly subscription"
},
"choose_offer": {
Expand Down
2 changes: 2 additions & 0 deletions platforms/web/public/locales/es/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"waiting_for_payment": "Esperando el pago",
"welcome_description": "Gracias por suscribirte a {{siteName}}. Disfruta de todo nuestro contenido.",
"welcome_title": "Bienvenido/a a {{siteName}}",
"payment_successful_title": "Pago exitoso",
"payment_successful_description": "Gracias por tu suscripción, disfruta de todo nuestro contenido.",
"yearly": "Suscripción anual"
},
"choose_offer": {
Expand Down
Loading

0 comments on commit a3b6c71

Please sign in to comment.