Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions blocks v2 #1768

Merged
merged 10 commits into from
Nov 15, 2023
4 changes: 2 additions & 2 deletions blocks/identity-block/features/signup/default.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ const SignUp = ({ customFields, arcSite }) => {
},
specialCharacters: {
value: pwSpecialCharacters,
message: phrases.t("identity-block.password-requirements-uppercase", {
requirementCount: pwUppercase,
message: phrases.t("identity-block.password-requirements-special", {
requirementCount: pwSpecialCharacters,
}),
},
},
Expand Down
6 changes: 6 additions & 0 deletions blocks/identity-block/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import useIdentity from "./components/identity";

export {
// eslint-disable-next-line import/prefer-default-export
useIdentity,
};
1 change: 1 addition & 0 deletions blocks/subscriptions-block/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# `@wpmedia/subscriptions-block`
206 changes: 206 additions & 0 deletions blocks/subscriptions-block/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
@use "@wpmedia/arc-themes-components/scss";
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
vgalatro marked this conversation as resolved.
Show resolved Hide resolved

.b-checkout {
&__cart {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-cart");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-cart");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__cart-items {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-cart-items");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-cart-items");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__cart-item {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-cart-item");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-cart-item");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved

&--name {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-cart-item--name");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-cart-item--name");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--info {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-cart-item--info");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-cart-item--info");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}
}

&__contact-info {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-contact-info");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-contact-info");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved

&-profile {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-contact-info-profile");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-contact-info-profile");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}
}

&__identity-row {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-identity-row");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-identity-row");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__identity-icon {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-identity-icon");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-identity-icon");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__payment {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved

&-form {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-form");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-form");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved

&--stripe-input-container {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-form--stripe-input-container");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-form--stripe-input-container");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--stripe-label {
nschubach marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-form--stripe-label");
nschubach marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-form--stripe-label");
nschubach marked this conversation as resolved.
Show resolved Hide resolved
}

&--stripe-element {
nschubach marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-form--stripe-element");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-form--stripe-element");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--stripe-cardDetails {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-form--stripe-cardDetails");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-form--stripe-cardDetails");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--stripe-countryDetails {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-form--stripe-countryDetails");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-form--stripe-countryDetails");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--stripe-row {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-form--stripe-row");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-form--stripe-row");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--border-bottom {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-form--border-bottom");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-form--border-bottom");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--border-right {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-form--border-right");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-form--border-right");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}
}

&-information {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-information");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-information");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}
}

&__test {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-test");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-test");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved

&-1 {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-test-1");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-test-1");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&-2 {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-test-2");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-test-2");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&-row {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("checkout-payment-test-row");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout-payment-test-row");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}
}

@include scss.block-components("checkout");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("checkout");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

.b-offer {
&__headings {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-headings");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-headings");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__title {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-title");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-title");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__subtitle {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-subtitle");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-subtitle");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__wrapper {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-wrapper");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-wrapper");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__children-grid {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-children-grid");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-children-grid");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__grid-list {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-grid-list");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-grid-list");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved

&--1 {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-grid-list-1");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-grid-list-1");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--2 {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-grid-list-2");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-grid-list-2");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--3 {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-grid-list-3");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-grid-list-3");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--4 {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-grid-list-4");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-grid-list-4");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&--5 {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-grid-list-5");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-grid-list-5");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved

> * {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-grid-list-5-children");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-grid-list-5-children");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

&__card {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-card");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-card");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__card--features {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-card-features");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-card-features");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

&__card--features--feature-item {
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-components("offer-card-features--feature-item");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer-card-features--feature-item");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}

@include scss.block-components("offer");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
@include scss.block-properties("offer");
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
}
108 changes: 108 additions & 0 deletions blocks/subscriptions-block/components/Cart/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React, { useEffect, useState } from "react";
vgalatro marked this conversation as resolved.
Show resolved Hide resolved
import PropTypes from "@arc-fusion/prop-types";
import { useFusionContext } from "fusion:context";
import getProperties from "fusion:properties";
import { usePhrases, Heading, Link } from "@wpmedia/arc-themes-components";
import useSales from "../useSales";
import currency from "../../utils/currency";
import Item from "./item";

const getPaymentInfo = ({ origin, endpoint, priceCode }) =>
fetch(`${origin}${endpoint}${priceCode}/1/${new Date().getTime()}`, {}).then((res) => res.json());
LauraPinilla marked this conversation as resolved.
Show resolved Hide resolved

const Cart = ({ offerURL, className }) => {
const { arcSite } = useFusionContext();
const phrases = usePhrases();

const [isFetching, setIsFetching] = useState(true);
const [cartItems, setCartItems] = useState();

const {
api: {
retail: { origin },
},
} = getProperties(arcSite);

const { Sales } = useSales();

useEffect(() => {
const fetchPaymentInfo = (priceCode) =>
getPaymentInfo({
origin,
endpoint: "/retail/public/v1/pricing/paymentInfo/",
priceCode,
});

const fetchCartItemSummaries = async (cartDetails) => {
const updatedCart = cartDetails;

if (!cartDetails.items) {
return cartDetails;
}

await Promise.all(
cartDetails.items.map((item) =>
fetchPaymentInfo(item.priceCode).then((priceSummary) => ({
...item,
priceSummary,
}))
)
).then((results) => {
updatedCart.items = results;
});

return updatedCart;
};

const getAllCart = async () => {
setCartItems(
await Sales.getCart()
.then(fetchCartItemSummaries)
.catch(() => [])
);
setIsFetching(false);
};

getAllCart();
}, [Sales, origin]);

if (isFetching) {
return null;
}

if (!cartItems?.items || !cartItems?.items.length) {
return (
<div className={`${className}__cart`}>
<Link href={offerURL}>{phrases.t("checkout-block.empty-cart-message")}</Link>
</div>
);
}

return (
<div className={`${className}__cart`}>
<Heading>{phrases.t("checkout-block.order-summary")}</Heading>
<div className={`${className}__cart-items`}>
{cartItems.items.map((itemDetails) => (
<Item
key={itemDetails.sku}
name={itemDetails.name}
description={itemDetails?.priceSummary?.pricingStrategy?.summary}
className={className}
/>
))}
<Item
name={phrases.t("checkout-block.due-today")}
description={`${currency(cartItems.currency)}${cartItems.total}`}
additionalInfo={phrases.t("checkout-block.plus-sales-tax")}
className={className}
/>
</div>
</div>
);
};

Cart.propTypes = {
offerURL: PropTypes.string.isRequired,
};

export default Cart;
Loading
Loading