From f60b373e2eed8a973141fc691c95f84e4538b162 Mon Sep 17 00:00:00 2001 From: "Carlos A. Cabrera" <316104+fnhipster@users.noreply.github.com> Date: Tue, 28 Jan 2020 13:36:06 -0600 Subject: [PATCH 01/17] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8dc5fc1..050f1d8 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [👉 Open Storybook](https://pmet-public.github.io/luma-ui/?path=/story/%F0%9F%91%8B-welcome--getting-started) +[🛍 Demo PWA Storefront](https://longliveluma.com) + ## Getting Started ```bash From 0e16d9237c83721b8b0417e2100ebf34f2d9ced8 Mon Sep 17 00:00:00 2001 From: "Carlos A. Cabrera" <316104+fnhipster@users.noreply.github.com> Date: Tue, 28 Jan 2020 13:36:35 -0600 Subject: [PATCH 02/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 050f1d8..014441c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Luma UI -[👉 Open Storybook](https://pmet-public.github.io/luma-ui/?path=/story/%F0%9F%91%8B-welcome--getting-started) +[📕 Open Storybook](https://pmet-public.github.io/luma-ui/?path=/story/%F0%9F%91%8B-welcome--getting-started) [🛍 Demo PWA Storefront](https://longliveluma.com) From afc938fdc7d15a3fc63592e41ae2a1191c3f53dd Mon Sep 17 00:00:00 2001 From: "Carlos A. Cabrera" <316104+fnhipster@users.noreply.github.com> Date: Tue, 28 Jan 2020 13:36:55 -0600 Subject: [PATCH 03/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 014441c..e9bcd25 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Luma UI -[📕 Open Storybook](https://pmet-public.github.io/luma-ui/?path=/story/%F0%9F%91%8B-welcome--getting-started) +[📕 UI Library Storybook](https://pmet-public.github.io/luma-ui/?path=/story/%F0%9F%91%8B-welcome--getting-started) [🛍 Demo PWA Storefront](https://longliveluma.com) From d95a7123ac8199cc73e61e8e05d6d9c6044bccec Mon Sep 17 00:00:00 2001 From: "Carlos A. Cabrera" Date: Sun, 2 Feb 2020 21:25:56 -0600 Subject: [PATCH 04/17] init --- src/components/CartSummary/CartSummary.tsx | 16 ++++ .../ApplyCouponsForm.story.tsx | 30 ++++++++ .../ApplyCouponsForm.styled.tsx | 12 +++ .../ApplyCouponsForm/ApplyCouponsForm.tsx | 76 +++++++++++++++++++ .../Checkout/ApplyCouponsForm/index.ts | 2 + 5 files changed, 136 insertions(+) create mode 100644 src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.story.tsx create mode 100644 src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.styled.tsx create mode 100644 src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.tsx create mode 100644 src/components/Checkout/ApplyCouponsForm/index.ts diff --git a/src/components/CartSummary/CartSummary.tsx b/src/components/CartSummary/CartSummary.tsx index f5b60c5..4ad67d9 100644 --- a/src/components/CartSummary/CartSummary.tsx +++ b/src/components/CartSummary/CartSummary.tsx @@ -2,6 +2,7 @@ import React from 'react' import { Component, Props } from '../../lib' import { Root, Title, PriceItem, Label } from './CartSummary.styled' import Price, { PriceProps } from '../Price' +import ApplyCouponsForm from '../Checkout/ApplyCouponsForm' type PriceItemProps = { label: string @@ -19,6 +20,21 @@ export const CartSummary: Component = ({ title, prices, ...pro {title.text} + { + throw Error('Oops!. There was an error... `cause your are just testing ;)') + }} + /> + {prices.map(({ label, price, appearance = 'normal' }, index) => ( diff --git a/src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.story.tsx b/src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.story.tsx new file mode 100644 index 0000000..53c0e0f --- /dev/null +++ b/src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.story.tsx @@ -0,0 +1,30 @@ +import React from 'react' +import ApplyCouponsForm from '.' +import { storiesOf } from '@storybook/react' +import { useForm, FormContext } from 'react-hook-form' +import { boolean } from '@storybook/addon-knobs' + +storiesOf('📦 Components/Checkout/ApplyCouponsForm', module).add('Default', () => { + const methods = useForm() + return ( + + { + throw Error('Oops!. There was an error... `cause your are just testing ;)') + }} + /> + + ) +}) diff --git a/src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.styled.tsx b/src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.styled.tsx new file mode 100644 index 0000000..5ec65dc --- /dev/null +++ b/src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.styled.tsx @@ -0,0 +1,12 @@ +import styled from 'styled-components' + +export const Root = styled.div` + display: grid; + grid-template-columns: 1fr auto; + align-items: center; +` + +export const Button = styled.button` + font-size: 1.2rem; + padding: 1rem 2rem; +` diff --git a/src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.tsx b/src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.tsx new file mode 100644 index 0000000..53109be --- /dev/null +++ b/src/components/Checkout/ApplyCouponsForm/ApplyCouponsForm.tsx @@ -0,0 +1,76 @@ +import React, { useState, useCallback } from 'react' +import { Component } from '../../../lib' +import { Root, Button } from './ApplyCouponsForm.styled' +import Form, { Input, InputProps } from '../../Form' +import { useForm } from 'react-hook-form' +import ButtonComponent, { ButtonProps } from '../../Button' + +export type ApplyCouponsFormPayload = { + giftCardCode: string + couponCode: string +} + +export type ApplyCouponsFormProps = { + submitButton: ButtonProps + onSubmit: (payload: ApplyCouponsFormPayload) => any + loading?: boolean + fields: { + giftCardCode: InputProps + couponCode: InputProps + } +} +export const ApplyCouponsForm: Component = ({ + fields, + submitButton, + onSubmit, + loading, + ...props +}) => { + const { handleSubmit, register, errors, setError } = useForm() + + const [submitting, setSubmitting] = useState(false) + + const handleOnSubmit = useCallback( + async form => { + setError('giftCardCode', '', undefined) + setSubmitting(true) + + try { + await handleSubmit(onSubmit)(form) + setSubmitting(false) + } catch (error) { + setError('giftCardCode', '', error?.message) + setSubmitting(false) + } + }, + [handleSubmit, onSubmit] + ) + + const disabled = submitting + + return ( + + + +