-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feat: [Refinements] Creates ShippingSimulation
#183
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c71b478
Tweaks PDP grid
eduardoformiga 4f23cef
Creates shipping simulation component
eduardoformiga 9b5757c
Adds ShippingSimulation parts and styles
eduardoformiga 14aa177
Tweaks PDP grid
eduardoformiga 9440c50
Updates input text clear button control
eduardoformiga 2b9aec2
Adds conditional rendering and session checking
eduardoformiga b3a181c
Renames from Zip code to Postal Code
eduardoformiga 988b21a
Makes Postal Code link text uniform
eduardoformiga bfba7ac
Themification ShippingSimulation
eduardoformiga d5cdfe9
Organizes ShippingSimulation component
eduardoformiga 3db162a
Manages simulation state using single object
eduardoformiga 5fd821b
Adds CHANGELOG entry
eduardoformiga 4c97ef3
Creates Stories
eduardoformiga 9e4d37d
Merge branch 'main' into feat/fs-475-shipping-simulation
eduardoformiga e32e892
removes stories folder
eduardoformiga ef62685
Fixes sonarQube
eduardoformiga 21fd149
Trigger CI
eduardoformiga 551a7be
Merge branch 'main' into feat/fs-475-shipping-simulation
eduardoformiga 3ccae86
Extracts code into new hook that uses useReducer
eduardoformiga b1c1185
Merge branch 'main' into feat/fs-475-shipping-simulation
eduardoformiga 3e02ec1
Removes -tablet from tokens
eduardoformiga da23293
Tweaks border radius
eduardoformiga cac3156
Tweaks font-size token
eduardoformiga 2eef085
Removes too specific token
eduardoformiga c67e72e
Merge branch 'main' into feat/fs-475-shipping-simulation
eduardoformiga 015bab6
Tweaks tokens spaces
eduardoformiga 64c74f6
Removes SessionProvider from stories
eduardoformiga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
153 changes: 153 additions & 0 deletions
153
src/components/ui/ShippingSimulation/ShippingSimulation.stories.mdx
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,153 @@ | ||
import { Meta, Canvas, Story, ArgsTable } from '@storybook/addon-docs' | ||
import ShippingSimulation from '.' | ||
import { | ||
TokenTable, | ||
TokenRow, | ||
TokenDivider, | ||
} from 'src/../.storybook/components' | ||
|
||
<Meta | ||
title="Features/ShippingSimulation" | ||
component={ShippingSimulation} | ||
argTypes={{ | ||
testId: { | ||
table: { | ||
disable: true, | ||
}, | ||
}, | ||
}} | ||
/> | ||
|
||
export const TemplateProvider = (args) => { | ||
return <ShippingSimulation {...args} style={{ border: 0 }} /> | ||
} | ||
|
||
<header> | ||
|
||
# Shipping Simulation | ||
|
||
This feature lets customers set the `PostalCode` and see the shipping options in the `PDP`. | ||
|
||
</header> | ||
|
||
## Overview | ||
|
||
The `ShippingSimulation` component uses [FastStore UI Table](https://www.faststore.dev/reference/ui/molecules/Table), and [InputText](/docs/atoms-inputtext-⚠%EF%B8%8F--default) as base. | ||
|
||
### Steps | ||
|
||
1. First, the available `ShippingSimulation` loads if any `PostalCode` is set using the [Regionalization](/docs/features-regionalization-overview--default-button). | ||
2. If there is no `PostalCode` in the [Regionalization](/docs/features-regionalization-overview--default-button), the user can set the desired shipping `PostalCode`. | ||
3. Updates `ShippingSimulation`. | ||
4. Gets notified if there are no available options. | ||
|
||
--- | ||
|
||
## Usage | ||
|
||
`import ShippingSimulation from 'src/components/ui/ShippingSimulation'` | ||
|
||
<Canvas> | ||
<Story name="default">{TemplateProvider.bind({})}</Story> | ||
</Canvas> | ||
|
||
<TokenTable> | ||
<TokenRow | ||
token="--fs-shipping-simulation-font-size" | ||
value="var(--fs-text-size-legend)" | ||
/> | ||
<TokenDivider /> | ||
<TokenRow | ||
token="--fs-shipping-simulation-padding" | ||
value="var(--fs-spacing-5)" | ||
/> | ||
<TokenRow | ||
token="--fs-shipping-simulation-border-width" | ||
value="var(--fs-border-width)" | ||
/> | ||
<TokenRow | ||
token="--fs-shipping-simulation-border-color" | ||
value="var(--fs-border-color-light)" | ||
isColor | ||
/> | ||
<TokenRow | ||
token="--fs-shipping-simulation-border-radius-bottom" | ||
value="var(--fs-border-radius)" | ||
/> | ||
</TokenTable> | ||
|
||
--- | ||
|
||
## Nested Elements | ||
|
||
### Title | ||
|
||
<TokenTable> | ||
<TokenRow | ||
token="--fs-shipping-simulation-title-padding-bottom" | ||
value="var(--fs-spacing-2)" | ||
/> | ||
</TokenTable> | ||
|
||
### Link | ||
|
||
<TokenTable> | ||
<TokenRow | ||
token="--fs-shipping-simulation-link-padding-top" | ||
value="var(--fs-spacing-1)" | ||
/> | ||
<TokenRow | ||
token="--fs-shipping-simulation-link-padding-bottom" | ||
value="var(--fs-spacing-4)" | ||
/> | ||
</TokenTable> | ||
|
||
### Subtitle | ||
|
||
<TokenTable> | ||
<TokenRow | ||
token="--fs-shipping-simulation-subtitle-text-size" | ||
value="var(--fs-text-size-2)" | ||
/> | ||
<TokenRow | ||
token="--fs-shipping-simulation-subtitle-text-weight" | ||
value="var(--fs-text-weight-bold)" | ||
/> | ||
<TokenRow token="--fs-shipping-simulation-subtitle-line-height" value="1.5" /> | ||
</TokenTable> | ||
|
||
### Location | ||
|
||
<TokenTable> | ||
<TokenRow | ||
token="--fs-shipping-simulation-location-padding-bottom" | ||
value="var(--fs-spacing-2)" | ||
/> | ||
</TokenTable> | ||
|
||
### Table | ||
|
||
<TokenTable> | ||
<TokenRow | ||
token="--fs-shipping-simulation-table-row-bkg-color" | ||
value="var(--fs-color-main-0)" | ||
isColor | ||
/> | ||
<TokenRow | ||
token="--fs-shipping-simulation-table-row-even-bkg-color" | ||
value="transparent" | ||
/> | ||
<TokenDivider /> | ||
<TokenRow | ||
token="--fs-shipping-simulation-table-cell-padding" | ||
value="var(--fs-spacing-2)" | ||
/> | ||
<TokenRow | ||
token="--fs-shipping-simulation-table-cell-text-size" | ||
value="var(--fs-text-size-2)" | ||
/> | ||
<TokenRow | ||
token="--fs-shipping-simulation-table-cell-border-radius" | ||
value=".25rem" | ||
/> | ||
</TokenTable> |
107 changes: 107 additions & 0 deletions
107
src/components/ui/ShippingSimulation/ShippingSimulation.tsx
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,107 @@ | ||
import { Table, TableBody, TableCell, TableRow } from '@faststore/ui' | ||
import type { HTMLAttributes } from 'react' | ||
|
||
import Price from 'src/components/ui/Price' | ||
import { usePriceFormatter } from 'src/sdk/product/useFormattedPrice' | ||
|
||
import Icon from '../Icon' | ||
import InputText from '../InputText' | ||
import Link from '../Link' | ||
import styles from './shipping-simulation.module.scss' | ||
import { useShippingSimulation } from './useShippingSimulation' | ||
|
||
interface ShippingSimulationProps extends HTMLAttributes<HTMLDivElement> { | ||
/** | ||
* ID to find this component in testing tools (e.g.: cypress, | ||
* testing-library, and jest). | ||
*/ | ||
testId?: string | ||
} | ||
|
||
function ShippingSimulation({ | ||
testId = 'store-shipping-simulation', | ||
...otherProps | ||
}: ShippingSimulationProps) { | ||
const { dispatch, input, shippingSimulation, handleSubmit, handleOnInput } = | ||
useShippingSimulation() | ||
|
||
const { | ||
postalCode: shippingPostalCode, | ||
displayClearButton, | ||
errorMessage, | ||
} = input | ||
|
||
const { location: shippingLocation, options: shippingOptions } = | ||
shippingSimulation | ||
|
||
const formatter = usePriceFormatter() | ||
|
||
const hasShippingOptions = !!shippingOptions && shippingOptions.length > 0 | ||
|
||
return ( | ||
<section | ||
className={styles.fsShippingSimulation} | ||
data-fs-shipping-simulation | ||
data-fs-shipping-simulation-empty={!hasShippingOptions ? 'true' : 'false'} | ||
data-testid={testId} | ||
{...otherProps} | ||
> | ||
<h2 className="text__title-subsection" data-fs-shipping-simulation-title> | ||
Shipping | ||
</h2> | ||
|
||
<InputText | ||
actionable | ||
error={errorMessage} | ||
id="shipping-postal-code" | ||
label="Postal Code" | ||
value={shippingPostalCode} | ||
onInput={handleOnInput} | ||
onSubmit={handleSubmit} | ||
onClear={() => dispatch({ type: 'clear' })} | ||
displayClearButton={displayClearButton} | ||
/> | ||
|
||
<Link href="/" data-fs-shipping-simulation-link> | ||
{"I don't know my Postal Code"} | ||
<Icon name="ArrowSquareOut" width={18} height={18} /> | ||
</Link> | ||
|
||
{hasShippingOptions && ( | ||
<> | ||
<h3 data-fs-shipping-simulation-subtitle>Shipping options</h3> | ||
<p className="text__body" data-fs-shipping-simulation-location> | ||
{shippingLocation} | ||
</p> | ||
|
||
<Table data-fs-shipping-simulation-table> | ||
<TableBody> | ||
{shippingOptions.map((option) => ( | ||
<TableRow | ||
key={option.carrier} | ||
data-fs-shipping-simulation-table-row | ||
> | ||
<TableCell data-fs-shipping-simulation-table-cell> | ||
{option.carrier} | ||
</TableCell> | ||
<TableCell data-fs-shipping-simulation-table-cell> | ||
{option.estimate} | ||
</TableCell> | ||
<TableCell data-fs-shipping-simulation-table-cell> | ||
<Price | ||
formatter={formatter} | ||
value={option.price} | ||
SRText="price" | ||
/> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</> | ||
)} | ||
</section> | ||
) | ||
} | ||
|
||
export default ShippingSimulation |
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 @@ | ||
export { default } from './ShippingSimulation' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
never