[offers][feat] tweak breadcrumbs

pull/490/head
Yangshun Tay 3 years ago
parent 87efcc3932
commit 84396fb95c

@ -1,45 +1,50 @@
export type BreadcrumbStep = { import clsx from 'clsx';
import { ChevronRightIcon } from '@heroicons/react/20/solid';
export type BreadcrumbStep = Readonly<{
label: string; label: string;
step?: number; step?: number;
}; }>;
type BreadcrumbsProps = Readonly<{ type BreadcrumbsProps = Readonly<{
currentStep: number; currentStep: number;
setStep: (nextStep: number) => void; setStep: (nextStep: number) => void;
steps: Array<BreadcrumbStep>; steps: ReadonlyArray<BreadcrumbStep>;
}>; }>;
function getPrimaryText(text: string) {
return <p className="text-primary-700 text-sm">{text}</p>;
}
function getSlateText(text: string) {
return <p className="text-sm text-slate-400">{text}</p>;
}
function getTextWithLink(text: string, onClickHandler: () => void) {
return (
<p
className="hover:text-primary-700 cursor-pointer text-sm text-slate-400 hover:underline hover:underline-offset-2"
onClick={onClickHandler}>
{text}
</p>
);
}
export function Breadcrumbs({ steps, currentStep, setStep }: BreadcrumbsProps) { export function Breadcrumbs({ steps, currentStep, setStep }: BreadcrumbsProps) {
return ( return (
<div className="flex space-x-1"> <nav aria-label="Submit offer stages" className="inline-flex">
{steps.map(({ label, step }, index) => ( <ol className="mx-auto flex w-full space-x-2 sm:space-x-4" role="list">
<div key={label} className="flex space-x-1"> {steps.map(({ label, step }, index) => (
{step === currentStep <li key={step} className="flex items-center">
? getPrimaryText(label) {index > 0 && (
: step !== undefined <ChevronRightIcon
? getTextWithLink(label, () => setStep(step)) aria-hidden="true"
: getSlateText(label)} className="h-5 w-5 flex-shrink-0 text-slate-400"
{index !== steps.length - 1 && getSlateText('>')} />
</div> )}
))} <button
</div> aria-current={step === currentStep ? 'page' : undefined}
className={clsx(
'text-xs font-medium text-slate-600 sm:text-sm',
index > 0 && 'ml-4',
step != null ? 'hover:text-primary-500' : 'cursor-default',
step === currentStep && 'text-primary-500',
)}
type="button"
{...(step != null
? {
onClick: () => {
setStep(step);
},
}
: {})}>
{label}
</button>
</li>
))}
</ol>
</nav>
); );
} }

@ -266,65 +266,67 @@ export default function OffersSubmissionForm({
return ( return (
<div ref={pageRef} className="w-full overflow-y-scroll"> <div ref={pageRef} className="w-full overflow-y-scroll">
<div className="flex justify-center"> <div className="flex justify-center">
<div className="block w-full max-w-screen-md rounded-lg bg-white p-6 sm:p-10 sm:shadow-lg md:my-10"> <div className="block w-full max-w-screen-md overflow-hidden rounded-lg sm:shadow-lg md:my-10">
<div className="mb-8 flex justify-end"> <div className="bg-primary-100 flex justify-center px-4 py-4 sm:px-6 lg:px-8">
<Breadcrumbs <Breadcrumbs
currentStep={step} currentStep={step}
setStep={setStep} setStep={setStep}
steps={breadcrumbSteps} steps={breadcrumbSteps}
/> />
</div> </div>
<FormProvider {...formMethods}> <div className="bg-white p-6 sm:p-10">
<form <FormProvider {...formMethods}>
className="space-y-6 text-sm" <form
onSubmit={handleSubmit(onSubmit)}> className="space-y-6 text-sm"
{steps[step]} onSubmit={handleSubmit(onSubmit)}>
{step === 0 && ( {steps[step]}
<div className="flex justify-end"> {step === 0 && (
<Button <div className="flex justify-end">
disabled={false} <Button
icon={ArrowRightIcon} disabled={false}
label="Next" icon={ArrowRightIcon}
variant="primary" label="Next"
onClick={() => { variant="primary"
goToNextStep(step); onClick={() => {
gaEvent({ goToNextStep(step);
action: 'offers.profile_submission_navigate_next', gaEvent({
category: 'submission', action: 'offers.profile_submission_navigate_next',
label: 'Navigate next', category: 'submission',
}); label: 'Navigate next',
}} });
/> }}
</div> />
)} </div>
{step === 1 && ( )}
<div className="flex items-center justify-between"> {step === 1 && (
<Button <div className="flex items-center justify-between">
addonPosition="start" <Button
icon={ArrowLeftIcon} addonPosition="start"
label="Previous" icon={ArrowLeftIcon}
variant="secondary" label="Previous"
onClick={() => { variant="secondary"
setStep(step - 1); onClick={() => {
gaEvent({ setStep(step - 1);
action: 'offers.profile_submission_navigation_back', gaEvent({
category: 'submission', action: 'offers.profile_submission_navigation_back',
label: 'Navigate back', category: 'submission',
}); label: 'Navigate back',
}} });
/> }}
<Button />
disabled={isSubmitting || isSubmitSuccessful} <Button
icon={ArrowRightIcon} disabled={isSubmitting || isSubmitSuccessful}
isLoading={isSubmitting || isSubmitSuccessful} icon={ArrowRightIcon}
label="Submit" isLoading={isSubmitting || isSubmitSuccessful}
type="submit" label="Submit"
variant="primary" type="submit"
/> variant="primary"
</div> />
)} </div>
</form> )}
</FormProvider> </form>
</FormProvider>
</div>
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save