-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/shipping-option-header' of github.com:vtex-apps…
…/shipping-option-components into feature/shipping-option-header
- Loading branch information
Showing
27 changed files
with
949 additions
and
269 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export const getAddress = ( | ||
countryCode: string, | ||
zipCode: string, | ||
account: string | ||
) => | ||
fetch( | ||
`/api/checkout/pub/postal-code/${countryCode}/${zipCode}?an=${account}` | ||
).then((res) => res.json()) | ||
|
||
export const updateSession = ( | ||
zipCode: string, | ||
geoCoordinates: number[], | ||
pickup?: Pickup | ||
) => | ||
fetch('/api/sessions', { | ||
method: 'POST', | ||
body: `{"public":{"facets":{"value":"zip-code=${zipCode};coordinates=${geoCoordinates.join( | ||
',' | ||
)}${pickup ? `;pickupPoint=${pickup.pickupPoint.id}` : ''}"}}}`, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
|
||
export const getPickups = ( | ||
countryCode: string, | ||
zipCode: string, | ||
account: string | ||
) => | ||
fetch( | ||
`/api/checkout/pub/pickup-points?an=${account}&countryCode=${countryCode}&postalCode=${zipCode}` | ||
).then((res) => res.json()) |
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,72 @@ | ||
import React from 'react' | ||
import { useIntl } from 'react-intl' | ||
import { usePixel } from 'vtex.pixel-manager' | ||
|
||
import ShippingOptionDrawer from './ShippingOptionDrawer' | ||
import ShippingOptionButton from './ShippingOptionButton' | ||
import DeliverySelection from './DeliverySelection' | ||
import { DELIVER_DRAWER_PIXEL_EVENT_ID } from '../constants' | ||
import messages from '../messages' | ||
|
||
interface Props { | ||
isLoading: boolean | ||
addressLabel?: string | ||
onSubmit: () => void | ||
inputErrorMessage?: string | ||
onChange: (zipCode?: string) => void | ||
zipCode?: string | ||
selectedZipCode?: string | ||
compact: boolean | ||
} | ||
|
||
const DeliveryDrawer = ({ | ||
addressLabel, | ||
isLoading, | ||
onChange, | ||
onSubmit, | ||
inputErrorMessage, | ||
selectedZipCode, | ||
zipCode, | ||
compact, | ||
}: Props) => { | ||
const intl = useIntl() | ||
const { push } = usePixel() | ||
|
||
const onOpen = () => { | ||
push({ | ||
id: DELIVER_DRAWER_PIXEL_EVENT_ID, | ||
}) | ||
} | ||
|
||
return ( | ||
<ShippingOptionDrawer | ||
icon={ | ||
<ShippingOptionButton | ||
onClick={onOpen} | ||
loading={isLoading} | ||
value={addressLabel} | ||
placeholder={intl.formatMessage(messages.deliverToButtonPlaceholder)} | ||
label={intl.formatMessage(messages.deliverToButtonLabel)} | ||
compact={compact} | ||
/> | ||
} | ||
title={intl.formatMessage(messages.storeDeliverDrawerTitle)} | ||
customPixelEventId={DELIVER_DRAWER_PIXEL_EVENT_ID} | ||
onSubmit={onSubmit} | ||
inputErrorMessage={inputErrorMessage} | ||
isLoading={isLoading} | ||
> | ||
<DeliverySelection | ||
isLoading={isLoading} | ||
onChange={onChange} | ||
onSubmit={onSubmit} | ||
addressLabel={addressLabel} | ||
inputErrorMessage={inputErrorMessage} | ||
selectedZipCode={selectedZipCode} | ||
zipCode={zipCode} | ||
/> | ||
</ShippingOptionDrawer> | ||
) | ||
} | ||
|
||
export default DeliveryDrawer |
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,48 @@ | ||
import React from 'react' | ||
|
||
import PostalCodeInput from './PostalCodeInput' | ||
import SubmitButton from './SubmitButton' | ||
|
||
interface Props { | ||
onSubmit: (zipCode?: string) => void | ||
inputErrorMessage?: string | ||
zipCode?: string | ||
onChange: (zipCode?: string) => void | ||
addressLabel?: string | ||
selectedZipCode?: string | ||
isLoading: boolean | ||
} | ||
|
||
const DeliverySelection = ({ | ||
onSubmit, | ||
inputErrorMessage, | ||
zipCode, | ||
onChange, | ||
addressLabel, | ||
selectedZipCode, | ||
isLoading, | ||
}: Props) => { | ||
const newZipCodeTyped = zipCode !== selectedZipCode | ||
const shouldHideUpdateButton = (!zipCode || !newZipCodeTyped) && !isLoading | ||
|
||
return ( | ||
<div className="flex flex-column justify-between"> | ||
<PostalCodeInput | ||
zipCode={zipCode} | ||
onSubmit={onSubmit} | ||
errorMessage={inputErrorMessage} | ||
onChange={onChange} | ||
addressLabel={addressLabel} | ||
/> | ||
<div className="fixed left-0 bottom-0 w-100 flex justify-center mb7"> | ||
<SubmitButton | ||
isHidden={shouldHideUpdateButton} | ||
isLoading={isLoading} | ||
onSubmit={onSubmit} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default DeliverySelection |
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,90 @@ | ||
import React from 'react' | ||
import { useIntl } from 'react-intl' | ||
import { usePixel } from 'vtex.pixel-manager' | ||
|
||
import ShippingOptionDrawer from './ShippingOptionDrawer' | ||
import ShippingOptionButton from './ShippingOptionButton' | ||
import { STORE_DRAWER_PIXEL_EVENT_ID } from '../constants' | ||
import messages from '../messages' | ||
import PickupSelection from './PickupSelection' | ||
|
||
interface Props { | ||
isLoading: boolean | ||
addressLabel?: string | ||
onSubmit: () => void | ||
inputErrorMessage?: string | ||
onChange: (zipCode?: string) => void | ||
zipCode?: string | ||
selectedZipCode?: string | ||
selectedPickup?: Pickup | ||
pickups: Pickup[] | ||
onSelectPickup: (pickup: Pickup) => void | ||
compact: boolean | ||
} | ||
|
||
const PikcupDrawer = ({ | ||
addressLabel, | ||
isLoading, | ||
onChange, | ||
onSubmit, | ||
inputErrorMessage, | ||
selectedZipCode, | ||
zipCode, | ||
pickups, | ||
selectedPickup, | ||
onSelectPickup, | ||
compact, | ||
}: Props) => { | ||
const intl = useIntl() | ||
const { push } = usePixel() | ||
|
||
const onOpen = () => { | ||
push({ | ||
id: STORE_DRAWER_PIXEL_EVENT_ID, | ||
}) | ||
} | ||
|
||
const drawerTitleMessage = | ||
pickups.length > 0 | ||
? messages.pickupDrawerTitleFilled | ||
: messages.pickupDrawerTitleEmpty | ||
|
||
const storeLabel = selectedPickup | ||
? selectedPickup.pickupPoint.friendlyName | ||
: undefined | ||
|
||
return ( | ||
<ShippingOptionDrawer | ||
icon={ | ||
<ShippingOptionButton | ||
onClick={onOpen} | ||
loading={isLoading} | ||
value={storeLabel} | ||
placeholder={intl.formatMessage(messages.storeButtonPlaceHolder)} | ||
label={intl.formatMessage(messages.storeButtonLabel)} | ||
compact={compact} | ||
/> | ||
} | ||
title={intl.formatMessage(drawerTitleMessage)} | ||
customPixelEventId={STORE_DRAWER_PIXEL_EVENT_ID} | ||
onSubmit={onSubmit} | ||
inputErrorMessage={inputErrorMessage} | ||
isLoading={isLoading} | ||
> | ||
<PickupSelection | ||
isLoading={isLoading} | ||
onChange={onChange} | ||
onSubmit={onSubmit} | ||
addressLabel={addressLabel} | ||
inputErrorMessage={inputErrorMessage} | ||
selectedZipCode={selectedZipCode} | ||
zipCode={zipCode} | ||
pickups={pickups} | ||
selectedPickup={selectedPickup} | ||
onSelectPickup={onSelectPickup} | ||
/> | ||
</ShippingOptionDrawer> | ||
) | ||
} | ||
|
||
export default PikcupDrawer |
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,42 @@ | ||
import React from 'react' | ||
import { useCssHandles } from 'vtex.css-handles' | ||
|
||
import '../styles.css' | ||
|
||
interface Props { | ||
pickup: Pickup | ||
onClick: () => void | ||
selected: boolean | ||
} | ||
|
||
const CSS_HANDLES = ['pickupItem', 'pickupItemSelected'] as const | ||
|
||
const PickupItem = ({ pickup, onClick, selected }: Props) => { | ||
const { | ||
distance, | ||
pickupPoint: { | ||
friendlyName, | ||
address: { city, neighborhood, number, postalCode, street }, | ||
}, | ||
} = pickup | ||
|
||
const handle = useCssHandles(CSS_HANDLES) | ||
|
||
return ( | ||
<button | ||
className={`${handle.pickupItem} ${ | ||
selected ? handle.pickupItemSelected : '' | ||
} relative`} | ||
onClick={onClick} | ||
> | ||
<p className="f4 tl ma0 fw6 mb2">{friendlyName}</p> | ||
<p className="mid-gray f6 ma0 tl">{`${number} ${street}`}</p> | ||
<p className="mid-gray f6 ma0 tl">{`${neighborhood}, ${city}, ${postalCode}`}</p> | ||
<span className="mid-gray absolute top-1 right-1"> | ||
{distance.toFixed(1)} Km | ||
</span> | ||
</button> | ||
) | ||
} | ||
|
||
export default PickupItem |
Oops, something went wrong.