-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: moved session Storage to own file
- Loading branch information
1 parent
2f4ec22
commit 738cc37
Showing
5 changed files
with
63 additions
and
58 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
support-frontend/assets/pages/[countryGroupId]/checkout/helpers/sessionStorage.ts
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,47 @@ | ||
import { storage } from '@guardian/libs'; | ||
import { type InferInput, object, picklist, safeParse, string } from 'valibot'; | ||
|
||
/** | ||
* The Guardian Ad-Lite Landing Page sets the returnLink in sessionStorage | ||
* And the thank-you page reads it. | ||
*/ | ||
export const ReturnAddressSchema = object({ | ||
link: string(), | ||
}); | ||
export function setReturnAddress(link: InferInput<typeof ReturnAddressSchema>) { | ||
storage.session.set('returnAddress', link); | ||
} | ||
export function getReturnAddress() { | ||
const sessionStorageReturnAddress = storage.session.get('returnAddress'); | ||
const parsedReturnAddress = safeParse( | ||
ReturnAddressSchema, | ||
sessionStorageReturnAddress, | ||
); | ||
return parsedReturnAddress.success | ||
? parsedReturnAddress.output.link | ||
: 'https://www.theguardian.com'; | ||
} | ||
|
||
/** | ||
* The checkout page sets the order in sessionStorage | ||
* And the thank-you page reads it. | ||
*/ | ||
export const OrderSchema = object({ | ||
firstName: string(), | ||
email: string(), | ||
paymentMethod: picklist([ | ||
'Stripe', | ||
'StripeExpressCheckoutElement', | ||
'PayPal', | ||
'DirectDebit', | ||
'Sepa', | ||
'None', | ||
]), | ||
status: picklist(['success', 'pending']), | ||
}); | ||
export function setThankYouOrder(order: InferInput<typeof OrderSchema>) { | ||
storage.session.set('thankYouOrder', order); | ||
} | ||
export function unsetThankYouOrder() { | ||
storage.session.remove('thankYouOrder'); | ||
} |
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