diff --git a/src/app/marketing/_components/ChartPreview.tsx b/src/app/marketing/_components/ChartPreview.tsx new file mode 100644 index 0000000..560e29d --- /dev/null +++ b/src/app/marketing/_components/ChartPreview.tsx @@ -0,0 +1,101 @@ +"use client"; + +import { useIsMobile } from "@/hooks/use-mobile"; +import type { ApexOptions } from "apexcharts"; +import dynamic from "next/dynamic"; + +type PropsType = { + series: { x: string; y: number }[]; + title: string; +}; + +const Chart = dynamic(() => import("react-apexcharts"), { + ssr: false, +}); + +export function ChartPreview({ series, title }: PropsType) { + const isMobile = useIsMobile(); + + const options: ApexOptions = { + legend: { + show: false, + }, + colors: ["#5750F1"], + chart: { + height: 310, + type: "area", + toolbar: { + show: false, + }, + fontFamily: "inherit", + }, + fill: { + gradient: { + opacityFrom: 0.55, + opacityTo: 0, + }, + }, + responsive: [ + { + breakpoint: 1024, + options: { + chart: { + height: 300, + }, + }, + }, + { + breakpoint: 1366, + options: { + chart: { + height: 320, + }, + }, + }, + ], + stroke: { + curve: "smooth", + width: isMobile ? 2 : 3, + }, + grid: { + strokeDashArray: 5, + yaxis: { + lines: { + show: true, + }, + }, + }, + dataLabels: { + enabled: false, + }, + tooltip: { + marker: { + show: true, + }, + }, + xaxis: { + axisBorder: { + show: false, + }, + axisTicks: { + show: false, + }, + }, + }; + + return ( +
+ +
+ ); +} diff --git a/src/app/marketing/_components/ChartStep.tsx b/src/app/marketing/_components/ChartStep.tsx new file mode 100644 index 0000000..23d455c --- /dev/null +++ b/src/app/marketing/_components/ChartStep.tsx @@ -0,0 +1,127 @@ +"use client"; +import InputGroup from "@/components/FormElements/InputGroup"; +import { ShowcaseSection } from "@/components/Layouts/showcase-section"; + +import { TrashIcon } from "@/assets/icons"; +import FormFooter from "@/components/ui/FormFooter"; +import { FormErrorMessages } from "@/constants/Texts"; +import { ChartPreview } from "./ChartPreview"; +import useChartStepPresenter from "./useChartStepPresenter"; + +const ChartStep = () => { + const { + errors, + handleSubmit, + onSubmit, + register, + fields, + append, + remove, + watch, + } = useChartStepPresenter(); + + const chartTitle = watch("chart_title"); + const chartPoints = watch("chart_points"); + + return ( +
+
+ + + {errors.chart_title && ( +

+ {errors.chart_title.message} +

+ )} + + {errors.lost_amount && ( +

+ {errors.lost_amount.message} +

+ )} +
+ + p.x && p.y)} + title={chartTitle} + /> + + + {fields.map((field, index) => ( +
+ + + +
+ ))} + +
+
+
+
+ ); +}; + +export default ChartStep; diff --git a/src/app/marketing/_components/useChartStepPresenter.ts b/src/app/marketing/_components/useChartStepPresenter.ts new file mode 100644 index 0000000..8e2cf01 --- /dev/null +++ b/src/app/marketing/_components/useChartStepPresenter.ts @@ -0,0 +1,45 @@ +"use client"; +import { useFieldArray, useForm } from "react-hook-form"; + +export interface IChartStepFields { + chart_title: string; + lost_amount: number; + chart_points: { x: string; y: number }[]; +} + +const useChartStepPresenter = () => { + const { + register, + handleSubmit, + control, + watch, + formState: { errors }, + } = useForm({ + defaultValues: { + chart_points: [{ x: "", y: 0 }], + }, + }); + + const { fields, append, remove } = useFieldArray({ + control, + name: "chart_points", + }); + + const onSubmit = (data: IChartStepFields) => { + console.log(data); + }; + + return { + register, + handleSubmit, + errors, + onSubmit, + fields, + append, + remove, + control, + watch, + }; +}; + +export default useChartStepPresenter; diff --git a/src/app/marketing/page.tsx b/src/app/marketing/page.tsx index ff2d2a2..035eb02 100644 --- a/src/app/marketing/page.tsx +++ b/src/app/marketing/page.tsx @@ -4,6 +4,7 @@ import Stepper, { Step } from "@/components/ui/Stepper"; import { BreadcrumbItem } from "@/types/shared"; import { useState } from "react"; import { ShowcaseSection } from "../../components/Layouts/showcase-section"; +import ChartStep from "./_components/ChartStep"; import HeroStep from "./_components/HeroStep"; const Marketing = () => { @@ -25,9 +26,9 @@ const Marketing = () => { content: , }, { - title: "Profile", - description: "Setup your profile", - content:
step 2
, + title: "Chart", + description: "Create the chart", + content: , }, { title: "Preferences", diff --git a/src/components/ui-elements/button.tsx b/src/components/ui-elements/button.tsx index a66c168..1b6ae90 100644 --- a/src/components/ui-elements/button.tsx +++ b/src/components/ui-elements/button.tsx @@ -37,6 +37,7 @@ type ButtonProps = HTMLAttributes & VariantProps & { label: string; icon?: React.ReactNode; + type?: "button" | "submit" | "reset"; }; export function Button({