From 1a6eb7e2ff0bf551e1560c67170e90fa8ec2a8ea Mon Sep 17 00:00:00 2001
From: Joe Carstairs <118172583+jcarstairs-scottlogic@users.noreply.github.com>
Date: Thu, 25 Jan 2024 16:59:42 +0000
Subject: 33 / Pay annual subscription by PayPal (#68)
* Refactors paypal-buttons -> paypal-product-buttons WebComponent
* Pulls out address to data file
* Defines annual subscription prices data hash
* Styles paypal-product-buttons
* Styles
* Details have cursor:pointer on the summary
* Moves Jyne section to separate page
* Rewrites payment options using details components
* Reworks translation typing
* Defines MembershipType enum
* Adds translations for MembershipType enum
* Can pay annual subs by PayPal
* Styles tables better
---
src/components/LallansIssue.astro | 4 +-
src/components/Navbar/NavLinks.astro | 3 +-
src/components/PayPalButtons.astro | 150 ----------------
src/components/PaypalProductButtons.astro | 26 +++
src/components/Scotsoun.astro | 4 +-
src/data/contactDetails.ts | 16 ++
src/data/subscriptionPrices.ts | 7 +
src/enums/MembershipType.ts | 42 +++++
src/i18n/translate.ts | 28 +--
src/i18n/translations/components/breadcrumbs.ts | 20 +++
src/i18n/translations/enums/membershipType.ts | 21 +++
src/i18n/translations/pages/home.ts | 76 ---------
src/i18n/translations/pages/jyne.ts | 190 +++++++++++++++++++++
.../furthsettins/lallans/[issueNumber]/index.astro | 1 +
.../furthsettins/scotsoun/[scotsounId]/index.astro | 1 +
src/pages/[locale]/index.astro | 27 +--
src/pages/[locale]/jyne/index.astro | 104 +++++++++++
.../jyne/paypal/[membershipType]/index.astro | 41 +++++
.../jyne/paypal/[membershipType]/success.astro | 30 ++++
src/pages/[locale]/jyne/paypal/index.astro | 27 +++
src/scripts/wc/paypal-product-buttons.ts | 146 ++++++++++++++++
src/types/TranslationsDictionary.d.ts | 15 +-
22 files changed, 703 insertions(+), 276 deletions(-)
delete mode 100644 src/components/PayPalButtons.astro
create mode 100644 src/components/PaypalProductButtons.astro
create mode 100644 src/data/subscriptionPrices.ts
create mode 100644 src/enums/MembershipType.ts
create mode 100644 src/i18n/translations/enums/membershipType.ts
create mode 100644 src/i18n/translations/pages/jyne.ts
create mode 100644 src/pages/[locale]/jyne/index.astro
create mode 100644 src/pages/[locale]/jyne/paypal/[membershipType]/index.astro
create mode 100644 src/pages/[locale]/jyne/paypal/[membershipType]/success.astro
create mode 100644 src/pages/[locale]/jyne/paypal/index.astro
create mode 100644 src/scripts/wc/paypal-product-buttons.ts
(limited to 'src')
diff --git a/src/components/LallansIssue.astro b/src/components/LallansIssue.astro
index c8bc6eb..317ff2d 100644
--- a/src/components/LallansIssue.astro
+++ b/src/components/LallansIssue.astro
@@ -7,7 +7,7 @@ import type LallansIssue from '$types/LallansIssue';
import { Image } from 'astro:assets';
import LallansIssueContributions from './LallansIssueContributions.astro';
import LallansIssueContributors from './LallansIssueContributors.astro';
-import PayPalButtons from './PayPalButtons.astro';
+import PaypalProductButtons from './PaypalProductButtons.astro';
interface Props {
issue: LallansIssue;
@@ -27,7 +27,7 @@ const t = translate(locale);
-
{t(tFurthsettins, { key: 'title' })}
- {t(tHame, { key: 'jyne' })}
+ {t(tJyne, { key: 'title' })}
{t(tHame, { key: 'contact' })}
diff --git a/src/components/PayPalButtons.astro b/src/components/PayPalButtons.astro
deleted file mode 100644
index cdea5cb..0000000
--- a/src/components/PayPalButtons.astro
+++ /dev/null
@@ -1,150 +0,0 @@
----
-import env from '$lib/env';
-import type Price from '$types/Price';
-
-interface Props {
- successPageUrl: string;
- productDescription: string;
- shortDescription: string;
- totalPrice: Price;
-}
-
-const { successPageUrl, productDescription, shortDescription, totalPrice } = Astro.props;
-
-const PAYPAL_CLIENT_ID =
- env.ENVIRONMENT === 'prod' ? env.PAYPAL_LIVE_CLIENT_ID : env.PAYPAL_SANDBOX_CLIENT_ID;
----
-
-
-
-
-
-
diff --git a/src/components/PaypalProductButtons.astro b/src/components/PaypalProductButtons.astro
new file mode 100644
index 0000000..0ebbd3f
--- /dev/null
+++ b/src/components/PaypalProductButtons.astro
@@ -0,0 +1,26 @@
+---
+import env from '$lib/env';
+import type Price from '$types/Price';
+
+interface Props {
+ successPageUrl: string;
+ productDescription: string;
+ shortDescription: string;
+ totalPrice: Price;
+}
+
+const { successPageUrl, productDescription, shortDescription, totalPrice } = Astro.props;
+
+const PAYPAL_CLIENT_ID =
+ env.ENVIRONMENT === 'prod' ? env.PAYPAL_LIVE_CLIENT_ID : env.PAYPAL_SANDBOX_CLIENT_ID;
+---
+
+
+ Loading PayPal buttons…
+
diff --git a/src/components/Scotsoun.astro b/src/components/Scotsoun.astro
index cca330d..7acae8b 100644
--- a/src/components/Scotsoun.astro
+++ b/src/components/Scotsoun.astro
@@ -4,7 +4,7 @@ import translate from '$i18n/translate';
import tSite from '$i18n/translations/site';
import tComponent from '$i18n/translations/components/scotsoun';
import type Scotsoun from '$types/Scotsoun';
-import PayPalButtons from './PayPalButtons.astro';
+import PaypalProductButtons from './PaypalProductButtons.astro';
import relativePath from '$lib/relativePath';
import { getLocaleFromPathOrThrow } from '$lib/getLocaleFromPath';
@@ -27,7 +27,7 @@ const t = translate(locale);
-
= TranslationsDictionary<{
- [key in Key]: { [locale in typeof defaultLocale]: Translation } & {
- [locale in Locale]?: Translation;
- };
+ [key in Key]: LocalesTranslationHash;
}>;
export default function (locale: Locale) {
- return function <
- Key extends string,
- Params,
- Dict extends TranslationsDictionaryWith,
- >(dict: Dict, params: { key: Key } & { [Param in keyof Params]: string }) {
+ return function (
+ dict: TranslationsDictionaryWith,
+ params: { key: Key } & ParamsHash
+ ) {
if (!(params.key in dict)) {
throw new Error(`
Could not find translation for key '${params.key}'. Available keys were:
@@ -26,7 +26,9 @@ export default function (locale: Locale) {
.join(', ')}
`);
}
- const translation = dict[params.key][locale] ?? dict[params.key][defaultLocale];
+ const localesTranslationHash: LocalesTranslationHash = dict[params.key];
+ const translation: Translation =
+ localesTranslationHash[locale] ?? localesTranslationHash[defaultLocale];
return translation(params);
};
}
diff --git a/src/i18n/translations/components/breadcrumbs.ts b/src/i18n/translations/components/breadcrumbs.ts
index 5aeff0e..8e3d027 100644
--- a/src/i18n/translations/components/breadcrumbs.ts
+++ b/src/i18n/translations/components/breadcrumbs.ts
@@ -22,6 +22,26 @@ const tBreadcrumbs = {
sco: () => 'Scotsoun',
'en-GB': () => 'Scotsoun',
},
+ '/jyne/': {
+ sco: () => 'Jyne',
+ 'en-GB': () => 'Join',
+ },
+ '/jyne/paypal/': {
+ sco: () => 'PayPal',
+ 'en-GB': () => 'PayPal',
+ },
+ '/jyne/paypal/individual-uk/': {
+ sco: () => 'Individual (UK)',
+ 'en-GB': () => 'Individual (UK)',
+ },
+ '/jyne/paypal/individual-non-uk/': {
+ sco: () => 'Individual (non-UK)',
+ 'en-GB': () => 'Individual (non-UK)',
+ },
+ '/jyne/paypal/institution-uk/': {
+ sco: () => 'Institutional (UK)',
+ 'en-GB': () => 'Institutional (UK)',
+ },
'/news/': {
sco: () => 'News',
'en-GB': () => 'News',
diff --git a/src/i18n/translations/enums/membershipType.ts b/src/i18n/translations/enums/membershipType.ts
new file mode 100644
index 0000000..0e1db06
--- /dev/null
+++ b/src/i18n/translations/enums/membershipType.ts
@@ -0,0 +1,21 @@
+import type { TranslationsDictionary, LocalesTranslationHash } from '$types/TranslationsDictionary';
+
+import MembershipType from '$enums/MembershipType';
+
+const tEnum: { [key in MembershipType]: LocalesTranslationHash