-
Notifications
You must be signed in to change notification settings - Fork 124
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: adding new free shipping bar functionality #177
base: main
Are you sure you want to change the base?
Changes from 2 commits
4f72859
4b4cfcf
272735a
cb712c6
daff60d
43d70e5
c253ae7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Icon from "deco-sites/fashion/components/ui/Icon.tsx"; | ||
import { useCart } from "deco-sites/std/commerce/vtex/hooks/useCart.ts"; | ||
|
||
import { formatPrice } from "deco-sites/fashion/sdk/format.ts"; | ||
|
||
export interface Props { | ||
value?: number; | ||
} | ||
|
||
function FreeShippingBar({ value }: Props) { | ||
const { cart } = useCart(); | ||
|
||
const locale = cart.value?.clientPreferencesData.locale; | ||
const currencyCode = cart.value?.storePreferencesData.currencyCode; | ||
|
||
const total = cart.value?.totalizers.find((item) => item.id === "Items"); | ||
|
||
if (!total || !value) return null; | ||
|
||
const progress = ((total?.value / 100) / value) * 100; | ||
|
||
return ( | ||
<> | ||
<div className="pt-4 mx-4"> | ||
<div className="mb-2 text-[#1A7346]"> | ||
<Icon | ||
className="mr-2 inline-block" | ||
id="TruckShippingBar" | ||
size={21} | ||
stroke="currentColor" | ||
strokeWidth={0} | ||
/> | ||
{progress < 100 | ||
? `Faltam R$ ${ | ||
formatPrice(value - total?.value / 100, currencyCode!, locale) | ||
} para o frete grátis` | ||
: "Parabéns! Você tem frete grátis"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about use a config key instead? you can let the user input a sort of export interface Messages {
leftTofreeShippingTemplate: string // "Faltam {currency} {value} para o frete grátis"
freeShipping: string // "Parabéns! Você tem frete grátis"
}
export interface Props {
value?: number;
messages: Messages;
} Then you can replace when using it const leftToShipping = props.message.leftToShippingTemplate.replace("{currency}", currencyCode).replace("{value}", formatPrice(value - total?.value / 100, currencyCode!, locale)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mcandeia makes a lot of sense... improvements completed |
||
</div> | ||
<div | ||
className="bg-[#D4DBD7] h-2.5 rounded-full" | ||
style={{ width: `100%` }} | ||
> | ||
<div | ||
className="max-w-full bg-[#1A7346] h-2.5 rounded-full after:content-[''] after:h-[10px] after:w-[10px] after:ml-0.5 after:bg-[#FFFFFF] after:block after:rounded-full after:float-right block" | ||
style={{ width: `${progress}%` }} | ||
> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default FreeShippingBar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import FreeShippingBar from "deco-sites/fashion/components/minicart/FreeShippingBar.tsx"; | ||
import type { Props } from "deco-sites/fashion/components/minicart/FreeShippingBar.tsx"; | ||
|
||
function FreeShippingBarSection(props: Props) { | ||
return <FreeShippingBar {...props} />; | ||
} | ||
|
||
export default FreeShippingBarSection; |
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.
since this component will likely be used by a huge amount of people, I think it may worth to add at least short descriptions here
e.g.: https://github.com/deco-sites/fashion/blob/main/components/header/Header.tsx#L34
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.
@mcandeia ahh, yes... great suggestion