From 64c5ee53a0d158b38caff3285dac008826d7ae88 Mon Sep 17 00:00:00 2001
From: Joe Carstairs <65492573+joeacarstairs@users.noreply.github.com>
Date: Thu, 25 Jan 2024 17:02:50 +0000
Subject: Update from staging (#70)
* 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
* Replaces a few straggler --margins with --spacing (#67)
---------
Co-authored-by: Joe Carstairs <118172583+jcarstairs-scottlogic@users.noreply.github.com>
---
scss/base/_address.scss | 5 +
scss/base/_details.scss | 4 +
scss/base/_index.scss | 5 +
scss/base/_paypal-product-buttons.scss | 4 +
scss/base/_table.scss | 23 +++
scss/modules/_index.scss | 1 +
scss/modules/_link-gallery.xs.scss | 2 +-
scss/modules/_nav.scss | 2 +-
scss/modules/_nav.sm.scss | 2 +-
scss/modules/_payment-methods-list.scss | 8 +
scss/modules/_product.scss | 2 +-
scss/modules/_schedule.scss | 4 +-
scss/modules/_skip-to-content.scss | 4 +-
scss/values/spacing/_constants.scss | 2 +-
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 +-
tsconfig.json | 1 +
37 files changed, 763 insertions(+), 285 deletions(-)
create mode 100644 scss/base/_address.scss
create mode 100644 scss/base/_details.scss
create mode 100644 scss/base/_paypal-product-buttons.scss
create mode 100644 scss/base/_table.scss
create mode 100644 scss/modules/_payment-methods-list.scss
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
diff --git a/scss/base/_address.scss b/scss/base/_address.scss
new file mode 100644
index 0000000..0206b83
--- /dev/null
+++ b/scss/base/_address.scss
@@ -0,0 +1,5 @@
+address {
+ margin-block: var(--spacing-block-md);
+ font-style: normal;
+ margin-inline-start: var(--spacing-inline-lg);
+}
diff --git a/scss/base/_details.scss b/scss/base/_details.scss
new file mode 100644
index 0000000..6d0b1d4
--- /dev/null
+++ b/scss/base/_details.scss
@@ -0,0 +1,4 @@
+details summary {
+ cursor: pointer;
+}
+
diff --git a/scss/base/_index.scss b/scss/base/_index.scss
index f338772..527b4c7 100644
--- a/scss/base/_index.scss
+++ b/scss/base/_index.scss
@@ -1,4 +1,9 @@
+@use 'address';
+@use 'details';
@use 'dl';
@use 'list';
+@use 'paypal-product-buttons';
+@use 'table';
@use 'theme';
@use 'typography';
+
diff --git a/scss/base/_paypal-product-buttons.scss b/scss/base/_paypal-product-buttons.scss
new file mode 100644
index 0000000..7339ede
--- /dev/null
+++ b/scss/base/_paypal-product-buttons.scss
@@ -0,0 +1,4 @@
+paypal-product-buttons div {
+ margin-block-start: var(--spacing-block-md);
+}
+
diff --git a/scss/base/_table.scss b/scss/base/_table.scss
new file mode 100644
index 0000000..ca4f957
--- /dev/null
+++ b/scss/base/_table.scss
@@ -0,0 +1,23 @@
+table {
+ border-collapse: collapse;
+ background-color: var(--background-color); // side-scrolling may be needed on narrow screens
+
+ caption {
+ font-style: italic;
+ font-size: var(--font-size-0);
+ }
+}
+
+thead, th {
+ border-block-end: var(--border-width) solid var(--text-color);
+}
+
+:is(th, td) {
+ padding-inline: var(--spacing-inline-sm);
+ padding-block: var(--spacing-block-sm);
+
+ + :is(th, td) {
+ border-inline-start: calc(var(--border-width) / 2) solid var(--text-color);
+ }
+}
+
diff --git a/scss/modules/_index.scss b/scss/modules/_index.scss
index 6e67241..822295f 100644
--- a/scss/modules/_index.scss
+++ b/scss/modules/_index.scss
@@ -5,6 +5,7 @@
@use 'link-gallery' as *;
@use 'nav' as *;
@use 'news-index' as *;
+@use 'payment-methods-list' as *;
@use 'product' as *;
@use 'schedule' as *;
@use 'skip-to-content' as *;
diff --git a/scss/modules/_link-gallery.xs.scss b/scss/modules/_link-gallery.xs.scss
index b2bf86c..805073d 100644
--- a/scss/modules/_link-gallery.xs.scss
+++ b/scss/modules/_link-gallery.xs.scss
@@ -1,7 +1,7 @@
.link-gallery {
grid-auto-rows: calc(
var(--gallery-row-image-height) +
- var(--margin-block-sm) +
+ var(--spacing-block-sm) +
var(--gallery-row-title-height)
);
--gallery-item-column-span: 2;
diff --git a/scss/modules/_nav.scss b/scss/modules/_nav.scss
index f2f32a9..e2c984e 100644
--- a/scss/modules/_nav.scss
+++ b/scss/modules/_nav.scss
@@ -1,6 +1,6 @@
.nav {
& > :not(:last-child) {
- margin-block: 0 var(--margin-block-sm);
+ margin-block: 0 var(--spacing-block-sm);
}
li {
diff --git a/scss/modules/_nav.sm.scss b/scss/modules/_nav.sm.scss
index db540bd..688f947 100644
--- a/scss/modules/_nav.sm.scss
+++ b/scss/modules/_nav.sm.scss
@@ -9,7 +9,7 @@
+ li::before {
content: '/';
- margin-inline: var(--margin-inline-md);
+ margin-inline: var(--spacing-inline-md);
}
}
}
diff --git a/scss/modules/_payment-methods-list.scss b/scss/modules/_payment-methods-list.scss
new file mode 100644
index 0000000..a59831a
--- /dev/null
+++ b/scss/modules/_payment-methods-list.scss
@@ -0,0 +1,8 @@
+.payment-methods-list {
+ list-style: none;
+
+ details[open] :last-child {
+ margin-block-end: var(--spacing-block-sm);
+ }
+}
+
diff --git a/scss/modules/_product.scss b/scss/modules/_product.scss
index bc05dfd..cb74573 100644
--- a/scss/modules/_product.scss
+++ b/scss/modules/_product.scss
@@ -10,7 +10,7 @@
flex-direction: column;
margin-inline: auto;
width: fit-content;
- gap: var(--margin-block-sm);
+ gap: var(--spacing-block-sm);
}
.product__action-block img {
diff --git a/scss/modules/_schedule.scss b/scss/modules/_schedule.scss
index 40a9fee..fcb1304 100644
--- a/scss/modules/_schedule.scss
+++ b/scss/modules/_schedule.scss
@@ -1,10 +1,10 @@
.schedule:not(:first-child) {
- margin-block-start: var(--margin-block-sm);
+ margin-block-start: var(--spacing-block-sm);
}
.schedule dt {
font-weight: 700;
- margin-block-start: var(--margin-block-sm);
+ margin-block-start: var(--spacing-block-sm);
text-align: center;
text-decoration: none;
}
diff --git a/scss/modules/_skip-to-content.scss b/scss/modules/_skip-to-content.scss
index a752b29..0a5f365 100644
--- a/scss/modules/_skip-to-content.scss
+++ b/scss/modules/_skip-to-content.scss
@@ -7,7 +7,7 @@
}
.skip-to-content:is(:focus, :focus-visible, :focus-within) {
- top: var(--margin-block-md);
+ top: var(--spacing-block-md);
opacity: 1;
transition: top 100ms;
-}
\ No newline at end of file
+}
diff --git a/scss/values/spacing/_constants.scss b/scss/values/spacing/_constants.scss
index 9a990b8..c89fdc8 100644
--- a/scss/values/spacing/_constants.scss
+++ b/scss/values/spacing/_constants.scss
@@ -42,7 +42,7 @@ $grid-padding-er: (
);
$spacing-factor: (
- 'inline': (lg: 4, md: 2, sm: 1),
+ 'inline': (lg: 12, md: 6, sm: 3),
'block': (lg: 16, md: 10, sm: 5)
);
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