Skip to content

Commit

Permalink
Merge branch 'feature/shipping-option-header' of github.com:vtex-apps…
Browse files Browse the repository at this point in the history
…/shipping-option-components into feature/shipping-option-header
  • Loading branch information
sheilagomes committed Aug 30, 2024
2 parents bc1a6f8 + ee28d01 commit 455b908
Show file tree
Hide file tree
Showing 27 changed files with 949 additions and 269 deletions.
6 changes: 4 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"vendor": "vtex",
"name": "shipping-option-zipcode",
"name": "shipping-option-components",
"version": "0.0.0",
"title": "Shipping Option Zipcode component",
"description": "Shipping Option Zipcode component",
Expand All @@ -13,7 +13,9 @@
"dependencies": {
"vtex.styleguide": "9.x",
"vtex.css-handles": "0.x",
"vtex.render-runtime": "8.x"
"vtex.render-runtime": "8.x",
"vtex.store-drawer": "0.x",
"vtex.pixel-manager": "1.x"
},
"registries": [
"smartcheckout"
Expand Down
3 changes: 2 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"store/shipping-option-zipcode.shippinFilter.pkcupAt.title": "Pickup at",
"store/shipping-option-zipcode.shippinFilter.pkcupAt.chooseAStore": "Choose a Store",
"store/shipping-option-zipcode.shippinFilter.pickupnearBy": "Pickup nearby",
"store/shipping-option-zipcode.shippinFilter.pickpu": "Pickup"
"store/shipping-option-zipcode.shippinFilter.pickpu": "Pickup",
"store/shipping-option-zipcode.updateButton.label": "Update"
}
3 changes: 2 additions & 1 deletion messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"store/shipping-option-zipcode.shippinFilter.pkcupAt.title": "Recogida en",
"store/shipping-option-zipcode.shippinFilter.pkcupAt.chooseAStore": "Selecciona una tienda",
"store/shipping-option-zipcode.shippinFilter.pickupnearBy": "Recogida cerca de",
"store/shipping-option-zipcode.shippinFilter.pickpu": "Recogida"
"store/shipping-option-zipcode.shippinFilter.pickpu": "Recogida",
"store/shipping-option-zipcode.updateButton.label": "Actualizar"
}
3 changes: 2 additions & 1 deletion messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"store/shipping-option-zipcode.shippinFilter.pkcupAt.title": "Retirar em",
"store/shipping-option-zipcode.shippinFilter.pkcupAt.chooseAStore": "Escolha uma loja",
"store/shipping-option-zipcode.shippinFilter.pickupnearBy": "Ponto de retirada mais próximo",
"store/shipping-option-zipcode.shippinFilter.pickpu": "Retirada"
"store/shipping-option-zipcode.shippinFilter.pickpu": "Retirada",
"store/shipping-option-zipcode.updateButton.label": "Atualizar"
}
32 changes: 32 additions & 0 deletions react/client.ts
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())
72 changes: 72 additions & 0 deletions react/components/DeliveryDrawer.tsx
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
48 changes: 48 additions & 0 deletions react/components/DeliverySelection.tsx
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
90 changes: 90 additions & 0 deletions react/components/PickupDrawer.tsx
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
42 changes: 42 additions & 0 deletions react/components/PickupItem.tsx
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
Loading

0 comments on commit 455b908

Please sign in to comment.