mirror of
https://github.com/vercel/commerce.git
synced 2025-07-28 20:51:23 +00:00
✨ feat: Checkout Page
:%s
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
.warpper{
|
||||
@apply w-full;
|
||||
padding: 3.2rem;
|
||||
.title{
|
||||
padding: 3.2rem 0;
|
||||
margin-bottom: 3.2rem;
|
||||
@apply flex justify-start items-center
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
import React, { useState } from 'react'
|
||||
import { Logo } from 'src/components/common'
|
||||
import CheckoutCollapse from 'src/components/common/CheckoutCollapse/CheckoutCollapse'
|
||||
import { removeItem } from 'src/utils/funtion.utils'
|
||||
import { CheckOutForm } from 'src/utils/types.utils'
|
||||
import s from './CheckoutInfo.module.scss'
|
||||
import CustomerInfoForm from './components/CustomerInfoForm/CustomerInfoForm'
|
||||
@@ -12,28 +13,41 @@ const CheckoutInfo = ({}: CheckoutInfoProps) => {
|
||||
const [active, setActive] = useState(1)
|
||||
const [done, setDone] = useState<number[]>([])
|
||||
const [info, setInfo] = useState<CheckOutForm>({})
|
||||
const onOpen = (id:number) => {
|
||||
setActive(id)
|
||||
}
|
||||
|
||||
const onEdit = (id:number) => {
|
||||
setActive(id)
|
||||
}
|
||||
|
||||
const onClose = (id:number) => {
|
||||
setActive(id)
|
||||
setDone(removeItem<number>(done,id))
|
||||
}
|
||||
|
||||
const onConfirm = (id:number,formInfo:CheckOutForm) => {
|
||||
if(id+1>formList.length){
|
||||
console.log({...info,...formInfo})
|
||||
}else{
|
||||
|
||||
setActive(id+1)
|
||||
if(done.length>0){
|
||||
for (let i = id+1; i <= formList.length; i++) {
|
||||
if(!done.includes(i)){
|
||||
setActive(i)
|
||||
}
|
||||
}
|
||||
}else{
|
||||
setActive(id+1)
|
||||
}
|
||||
setDone([...done,id])
|
||||
}
|
||||
setDone([...done,id])
|
||||
setInfo({...info,...formInfo})
|
||||
}
|
||||
|
||||
const getNote = (id:number) => {
|
||||
switch (id) {
|
||||
case 1:
|
||||
return `${info.name}, ${info.email}`
|
||||
case 2:
|
||||
return `${info.address}, ${info.state}, ${info.city}, ${info.code}, ${info.phone}, `
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
const formList = [
|
||||
{
|
||||
id: 1,
|
||||
@@ -57,6 +71,7 @@ const CheckoutInfo = ({}: CheckoutInfoProps) => {
|
||||
<Logo />
|
||||
</div>
|
||||
{formList.map((item) => {
|
||||
let note = getNote(item.id)
|
||||
return <CheckoutCollapse
|
||||
key={item.title}
|
||||
id={item.id}
|
||||
@@ -64,30 +79,11 @@ const CheckoutInfo = ({}: CheckoutInfoProps) => {
|
||||
title={item.title}
|
||||
onEditClick={onEdit}
|
||||
isEdit={done.includes(item.id)}
|
||||
note={note}
|
||||
>
|
||||
{item.form}
|
||||
</CheckoutCollapse>
|
||||
})}
|
||||
{/* <CheckoutCollapse
|
||||
id={1}
|
||||
visible={active === 1}
|
||||
// onOpen={onOpen}
|
||||
// onClose={onClose}
|
||||
title="Customer Information"
|
||||
isEdit={true}
|
||||
>
|
||||
<CustomerInfoForm />
|
||||
</CheckoutCollapse>
|
||||
<CheckoutCollapse
|
||||
id={2}
|
||||
visible={active === 2}
|
||||
// onOpen={onOpen2}
|
||||
// onClose={onClose2}
|
||||
title="Shipping Information"
|
||||
isEdit={true}
|
||||
>
|
||||
<ShippingInfoForm />
|
||||
</CheckoutCollapse> */}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@@ -1,9 +1,15 @@
|
||||
.warpper{
|
||||
.title{
|
||||
min-width: 19.4rem;
|
||||
@apply text-label;
|
||||
}
|
||||
.hightlight{
|
||||
@apply text-active;
|
||||
.info{
|
||||
.line{
|
||||
@apply flex justify-start items-center;
|
||||
.title{
|
||||
margin-right: 3.2rem;
|
||||
min-width: 19.4rem;
|
||||
@apply text-label;
|
||||
}
|
||||
.hightlight{
|
||||
@apply text-active;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,17 +5,19 @@ interface BankTransferProps {}
|
||||
const BankTransfer = ({}: BankTransferProps) => {
|
||||
return (
|
||||
<div className={s.warpper}>
|
||||
<div className={s.line}>
|
||||
<div className={s.title}>Account Name:</div>
|
||||
<div className={s.hightlight}>Duong Dinh Vu</div>
|
||||
</div>
|
||||
<div className={s.line}>
|
||||
<div className={s.title}>Account Number:</div>
|
||||
<div className={s.hightlight}>1234 1234 1234 1234</div>
|
||||
</div>
|
||||
<div className={s.line}>
|
||||
<div className={s.title}>Bank Name:</div>
|
||||
<div className={s.hightlight}>Techcombank - HCMC</div>
|
||||
<div className={s.info}>
|
||||
<div className={s.line}>
|
||||
<div className={s.title}>Account Name:</div>
|
||||
<div className={s.hightlight}>Duong Dinh Vu</div>
|
||||
</div>
|
||||
<div className={s.line}>
|
||||
<div className={s.title}>Account Number:</div>
|
||||
<div className={s.hightlight}>1234 1234 1234 1234</div>
|
||||
</div>
|
||||
<div className={s.line}>
|
||||
<div className={s.title}>Bank Name:</div>
|
||||
<div className={s.hightlight}>Techcombank - HCMC</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
@@ -0,0 +1,12 @@
|
||||
@import "../../../../../../styles/utilities";
|
||||
.warpper{
|
||||
@apply u-form;
|
||||
.line{
|
||||
>div{
|
||||
width: 50%;
|
||||
}
|
||||
}
|
||||
.checkbox{
|
||||
margin-top: 1.6rem;
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
import React, { useRef } from 'react'
|
||||
import { CheckboxCommon, Inputcommon } from 'src/components/common'
|
||||
import { CustomInputCommon } from 'src/utils/type.utils'
|
||||
import s from "./CreditCardForm.module.scss"
|
||||
interface CreditCardFormProps {
|
||||
|
||||
}
|
||||
|
||||
const CreditCardForm = ({}: CreditCardFormProps) => {
|
||||
const cardNumberRef = useRef<CustomInputCommon>(null)
|
||||
const dateRef = useRef<CustomInputCommon>(null)
|
||||
const cvsRef = useRef<CustomInputCommon>(null)
|
||||
return (
|
||||
<div className={s.warpper}>
|
||||
<div className={s.body}>
|
||||
<Inputcommon type="text" placeholder="Cârd Number" ref={cardNumberRef} />
|
||||
<div className={s.line}>
|
||||
<Inputcommon type="text" placeholder="MM/YY" ref={dateRef} />
|
||||
<Inputcommon type="text" placeholder="CVS" ref={cvsRef} />
|
||||
</div>
|
||||
</div>
|
||||
<div className={s.checkbox}><CheckboxCommon/></div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default CreditCardForm
|
@@ -0,0 +1,14 @@
|
||||
.wrapper{
|
||||
padding: 0 5.6rem;
|
||||
.inner{
|
||||
padding: 4rem 0;
|
||||
}
|
||||
.bottom{
|
||||
margin-top: 2.4rem;
|
||||
@apply flex justify-between items-center;
|
||||
.note{
|
||||
font-size: 1.2rem;
|
||||
line-height: 2rem;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,28 +1,55 @@
|
||||
import React from 'react'
|
||||
import { TabCommon, TabPane } from 'src/components/common'
|
||||
import { ButtonCommon, TabCommon, TabPane } from 'src/components/common'
|
||||
import { CheckOutForm } from 'src/utils/types.utils'
|
||||
import BankTransfer from '../BankTransfer/BankTransfer'
|
||||
import Link from 'next/link'
|
||||
|
||||
import s from "./PaymentInfoForm.module.scss"
|
||||
import s from './PaymentInfoForm.module.scss'
|
||||
import CreditCardForm from '../CreditCardForm/CreditCardForm'
|
||||
interface PaymentInfoFormProps {
|
||||
onConfirm?: (id:number,formInfo:CheckOutForm)=>void
|
||||
id:number
|
||||
onConfirm?: (id: number, formInfo: CheckOutForm) => void
|
||||
id: number
|
||||
}
|
||||
|
||||
const PaymentInfoForm = ({}: PaymentInfoFormProps) => {
|
||||
return (
|
||||
<div className="">
|
||||
<TabCommon>
|
||||
<TabPane tabName = "Bank Transfer">
|
||||
<BankTransfer/>
|
||||
</TabPane>
|
||||
<TabPane tabName = "Bank Transfer 2">
|
||||
<BankTransfer/>
|
||||
</TabPane>
|
||||
</TabCommon>
|
||||
|
||||
const PaymentInfoForm = ({onConfirm,id}: PaymentInfoFormProps) => {
|
||||
const handleConfirmClick = () => {
|
||||
onConfirm && onConfirm(id,{})
|
||||
}
|
||||
return (
|
||||
<div className={s.wrapper}>
|
||||
<TabCommon>
|
||||
<TabPane tabName="Bank Transfer">
|
||||
<div className={s.inner}><BankTransfer /></div>
|
||||
</TabPane>
|
||||
<TabPane tabName="Ewallet">
|
||||
<div className={s.inner}></div>
|
||||
</TabPane>
|
||||
<TabPane tabName="Credit Card">
|
||||
<div className={s.inner}><CreditCardForm /></div>
|
||||
</TabPane>
|
||||
</TabCommon>
|
||||
<div className={s.bottom}>
|
||||
<div className={s.note}>
|
||||
By clicking continue you agree to Casper's{' '}
|
||||
{
|
||||
<Link href="#">
|
||||
<strong>terms and conditions</strong>
|
||||
</Link>
|
||||
}{' '}
|
||||
and{' '}
|
||||
{
|
||||
<Link href="#">
|
||||
<strong>privacy policy </strong>
|
||||
</Link>
|
||||
}
|
||||
.
|
||||
</div>
|
||||
)
|
||||
<ButtonCommon onClick={handleConfirmClick}>
|
||||
Submit Order
|
||||
</ButtonCommon>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default PaymentInfoForm
|
||||
|
Reference in New Issue
Block a user