Skip to content

Commit

Permalink
feat: Customize labels on AvailabilityTemplate component
Browse files Browse the repository at this point in the history
  • Loading branch information
acasazza committed Sep 12, 2023
1 parent 5713ca9 commit 2c9e7ff
Show file tree
Hide file tree
Showing 12 changed files with 4,182 additions and 5,238 deletions.
25 changes: 14 additions & 11 deletions packages/docs/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// .storybook/main.ts
const config = {
stories: ['../stories/**/*.stories.mdx', '../stories/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
core: {
builder: '@storybook/builder-vite',
import type { StorybookConfig } from "@storybook/react-vite";
const config: StorybookConfig = {
stories: ["../stories/**/*.mdx", "../stories/**/*.stories.@(js|jsx|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/react-vite",
options: {},
},
async viteFinal(config) {
// Add your configuration here
return config;
docs: {
autodocs: "tag",
},
};

module.exports = config;
export default config;
56 changes: 31 additions & 25 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,41 @@
"description": "",
"main": "index.js",
"devDependencies": {
"@babel/core": "^7.20.2",
"@mdx-js/react": "^2.1.5",
"@storybook/addon-actions": "^6.5.13",
"@storybook/addon-backgrounds": "^6.5.13",
"@storybook/addon-docs": "^6.5.13",
"@storybook/addon-essentials": "^6.5.13",
"@storybook/addon-interactions": "^6.5.13",
"@storybook/addon-links": "^6.5.13",
"@storybook/addon-measure": "^6.5.13",
"@storybook/addon-outline": "^6.5.13",
"@storybook/addons": "^6.5.13",
"@storybook/builder-vite": "^0.2.5",
"@storybook/builder-webpack4": "^6.5.13",
"@storybook/client-api": "^6.5.13",
"@storybook/client-logger": "^6.5.13",
"@storybook/manager-webpack4": "^6.5.13",
"@storybook/react": "^6.5.13",
"@storybook/testing-library": "^0.0.13",
"@storybook/theming": "^6.5.13",
"@types/react": "^18.0.25",
"babel-loader": "^9.1.0",
"@babel/core": "^7.21.8",
"@mdx-js/react": "^2.3.0",
"@storybook/addon-actions": "^7.0.12",
"@storybook/addon-backgrounds": "^7.0.12",
"@storybook/addon-docs": "^7.0.12",
"@storybook/addon-essentials": "^7.0.12",
"@storybook/addon-interactions": "^7.0.12",
"@storybook/addon-links": "^7.0.12",
"@storybook/addon-measure": "^7.0.12",
"@storybook/addon-outline": "^7.0.12",
"@storybook/addons": "^7.0.12",
"@storybook/blocks": "^7.0.12",
"@storybook/builder-vite": "^7.0.12",
"@storybook/builder-webpack4": "^6.5.16",
"@storybook/client-api": "^7.0.12",
"@storybook/client-logger": "^7.0.12",
"@storybook/manager-webpack4": "^6.5.16",
"@storybook/react": "^7.0.12",
"@storybook/react-vite": "^7.0.12",
"@storybook/testing-library": "^0.2.0",
"@storybook/theming": "^7.0.12",
"@types/react": "^18.2.6",
"babel-loader": "^9.1.2",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^4.9.3"
"storybook": "^7.0.12",
"typescript": "^5.0.4"
},
"scripts": {
"test": "echo \"Error: no test specified\"",
"start": "start-storybook -p 6006",
"build": "build-storybook -s ./public --docs"
"build": "build-storybook -s ./public --docs",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"repository": {
"type": "git",
Expand All @@ -47,7 +53,7 @@
},
"homepage": "https://github.com/commercelayer/commercelayer-react-components#readme",
"dependencies": {
"@commercelayer/js-auth": "^2.3.0",
"@commercelayer/js-auth": "^4.0.0",
"@commercelayer/react-components": "workspace:*"
}
}
}
5 changes: 3 additions & 2 deletions packages/docs/stories/assets/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export const salesChannel = {
clientId: '48ee4802f8227b04951645a9b7c8af1e3943efec7edd1dcfd04b5661bf1da5db',
endpoint: 'https://the-blue-brand-3.commercelayer.co',
scope: 'market:58'
slug: 'the-blue-brand-3',
scope: 'market:58',
domain: 'commercelayer.co'
}

export const customer = {
Expand Down
30 changes: 19 additions & 11 deletions packages/docs/stories/hooks/useGetToken.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSalesChannelToken } from '@commercelayer/js-auth'
import { authentication } from '@commercelayer/js-auth'
import { useEffect, useState } from 'react'
import { customer, salesChannel } from '../assets/config'

Expand All @@ -14,8 +14,9 @@ export default function useGetToken<T extends UseGetTokenOptions>(
} {
const [token, setToken] = useState('')
const clientId = salesChannel.clientId
const endpoint = salesChannel.endpoint
const slug = salesChannel.slug
const scope = salesChannel.scope
const domain = salesChannel.domain
const user = options?.userMode
? {
username: customer.username,
Expand All @@ -24,20 +25,27 @@ export default function useGetToken<T extends UseGetTokenOptions>(
: undefined
useEffect(() => {
const getToken = async (): Promise<void> => {
const token = await getSalesChannelToken(
{
clientId,
endpoint,
scope
},
user
)
const token =
user == null
? await authentication('client_credentials', {
clientId,
slug,
scope,
domain
})
: await authentication('password', {
clientId,
slug,
scope,
domain,
...user
})
if (token) setToken(token.accessToken)
}
void getToken()
}, [])
return {
accessToken: token,
endpoint
endpoint: `https://${slug}.${domain}`
}
}
84 changes: 55 additions & 29 deletions packages/docs/stories/prices/Price.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
import { ComponentMeta, type ComponentStory } from '@storybook/react'

import type { Meta, StoryObj } from '@storybook/react'
import CommerceLayer from '@commercelayer/react-components/auth/CommerceLayer'
import Price from '@commercelayer/react-components/prices/Price'
import PricesContainer from '@commercelayer/react-components/prices/PricesContainer'
import { Price as PriceComponent } from '@commercelayer/react-components/prices/Price'
import useGetToken from '../hooks/useGetToken'
import { skus } from '../assets/config'
import React from 'react'

interface MetaProps {
/**
* The skuCode of the price to be fetched
*/
skuCode: string
accessToken?: string
endpoint?: string
}

const Story: ComponentMeta<typeof PriceComponent> = {
title: 'Components/Prices/Price',
component: PriceComponent,
const meta: Meta<MetaProps> = {
/* 👇 The title prop is optional.
* Seehttps://storybook.js.org/docs/react/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
title: 'Components/Price',
args: {
skuCode: 'BABYONBU000000E63E7412MX',
accessToken: undefined,
endpoint: undefined
},
argTypes: {
skuCode: {
description: 'SKU is a unique identifier, meaning Stock Keeping Unit.',
description: 'The skuCode of the price to be fetched',
type: { name: 'string', required: true },
defaultValue: 'BABYONBU000000E63E7412MX'
},
accessToken: {
description: 'The access token to be used for the API calls',
type: { name: 'string', required: false },
table: {
category: 'attributes'
}
defaultValue: undefined
},
showCompare: {
description: 'SKU is a unique identifier, meaning Stock Keeping Unit.',
type: { name: 'boolean', required: false },
table: {
category: 'attributes'
}
endpoint: {
description: 'The endpoint to be used for the API calls',
type: { name: 'string', required: false },
defaultValue: undefined
}
}
}

export default Story
export default meta
type Story = StoryObj<MetaProps>

const Template: ComponentStory<typeof PriceComponent> = (arg) => {
const config = useGetToken()
return (
<CommerceLayer {...config}>
<PricesContainer>
<PriceComponent {...arg} />
</PricesContainer>
</CommerceLayer>
)
// 👇 The PriceTemplate construct will be spread to the existing stories.
const PriceTemplate: Story = {
render: ({ skuCode, accessToken, endpoint }) => {
const { accessToken: defaultToken, endpoint: defaultEndpoint } =
useGetToken()
return (
<CommerceLayer
accessToken={accessToken ?? defaultToken}
endpoint={endpoint ?? defaultEndpoint}
>
<PricesContainer>
<Price skuCode={skuCode} />
</PricesContainer>
</CommerceLayer>
)
}
}

export const Price = Template.bind({})
Price.args = { skuCode: skus.withAvailabilities, showCompare: false }
export const GetSinglePrice = {
...PriceTemplate
}
36 changes: 0 additions & 36 deletions packages/docs/stories/prices/PricesContainer.stories.tsx

This file was deleted.

3 changes: 3 additions & 0 deletions packages/docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"compilerOptions": {
"jsx": "react",
"jsx": "react",
"jsx": "react",
"target": "es5",
"lib": [
"dom",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@
"peerDependencies": {
"react": "^18.0.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ export function BillingAddressForm(props: Props): JSX.Element {
// @ts-expect-error no type no types
)?.checked || getSaveBillingAddressToAddressBook()
if (reset && (!isEmpty(values) || !isEmpty(errors) || checkboxChecked)) {
if (saveAddressToCustomerAddressBook) {
saveAddressToCustomerAddressBook({
type: 'billing_address',
value: false
})
}
// if (saveAddressToCustomerAddressBook) {
// saveAddressToCustomerAddressBook({
// type: 'billing_address',
// value: false
// })
// }
if (ref) {
ref.current?.reset()
resetForm({ target: ref.current } as any)
Expand Down
Loading

0 comments on commit 2c9e7ff

Please sign in to comment.