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

fix: add missing labels to number input #1855

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/app/[locale]/(default)/product/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const getProduct = async (productPromise: ReturnType<typeof getProductData>) =>
const getFields = async (productPromise: ReturnType<typeof getProductData>) => {
const product = await productPromise;

return productOptionsTransformer(product.productOptions);
return await productOptionsTransformer(product.productOptions);
};

const getCtaLabel = async (productPromise: ReturnType<typeof getProductData>) => {
Expand Down
12 changes: 9 additions & 3 deletions core/data-transformers/product-options-transformer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { removeEdgesAndNodes } from '@bigcommerce/catalyst-client';
import { ResultOf } from 'gql.tada';
import { getTranslations } from 'next-intl/server';

import { Field } from '@/vibes/soul/sections/product-detail/schema';
import { ProductFormFragment } from '~/app/[locale]/(default)/product/[slug]/page-data';

export const productOptionsTransformer = (
export const productOptionsTransformer = async (
productOptions: ResultOf<typeof ProductFormFragment>['productOptions'],
) =>
removeEdgesAndNodes(productOptions)
) => {
const t = await getTranslations('Product.ProductDetails');

return removeEdgesAndNodes(productOptions)
.map<Field | null>((option) => {
if (option.__typename === 'MultipleChoiceOption') {
const values = removeEdgesAndNodes(option.values);
Expand Down Expand Up @@ -143,6 +146,8 @@ export const productOptionsTransformer = (
defaultValue: option.defaultNumber?.toString(),
min: option.lowest ?? undefined,
max: option.highest ?? undefined,
incrementLabel: t('increaseNumber'),
decrementLabel: t('decreaseNumber'),
// TODO: should we take into account other properties from API like isIntegerOnly, limitNumberBy?
// https://developer.bigcommerce.com/graphql-storefront/reference#definition-LimitInputBy
};
Expand Down Expand Up @@ -184,3 +189,4 @@ export const productOptionsTransformer = (
return null;
})
.filter((field) => field !== null);
};
2 changes: 2 additions & 0 deletions core/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@
"successMessage": "{cartItems, plural, =1 {1 item} other {# items}} added to <cartLink> your cart</cartLink>",
"missingCart": "Cart not found. Please try again later!",
"unknownError": "Unknown error. Please try again later.",
"increaseNumber": "Increase number",
"decreaseNumber": "Decrease number",
"thumbnail": "View image number",
"Submit": {
"addToCart": "Add to cart",
Expand Down
Loading