Skip to content

fix(ui): change `<input type="date"> to Datepicker #464

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@
"clsx": "^2.1.1",
"cmdk": "^1.0.0",
"cookie": "^0.6.0",
"date-fns": "^3.6.0",
"dayjs": "^1.11.11",
"hono": "^4.4.8",
"html-to-image": "^1.11.11",
@@ -102,6 +103,7 @@
"prisma-json-types-generator": "^3.0.4",
"pushmodal": "^1.0.4",
"react": "18.3.1",
"react-day-picker": "^8.10.1",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.51.5",
44 changes: 25 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions src/components/common/date-picker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"use client";

import { RiCalendar2Line as CalendarIcon } from "@remixicon/react";
import * as React from "react";

import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { cn } from "@/lib/utils";
import { format } from "date-fns";
import type { SelectSingleEventHandler } from "react-day-picker";

export type DatePickerProps = {
className?: string;
dateFormat?: string;
disabled?: boolean;
locale?: string;
selected: Date;
onSelect: SelectSingleEventHandler;
placeholder?: string;
};

const DatePicker = ({
className,
dateFormat,
disabled,
locale,
selected,
onSelect,
placeholder,
}: DatePickerProps) => {
return (
<Popover>
<PopoverTrigger asChild>
<Button
variant={"outline"}
className={cn(
"w-full text-left font-normal",
!selected && "text-muted-foreground",
)}
>
{selected ? format(selected, "PPP") : <span>Pick a date</span>}
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="single"
selected={new Date(selected)}
onSelect={onSelect}
disabled={(date) => {
if (disabled) return true;
return date > new Date() || date < new Date("1900-01-01");
}}
initialFocus
/>
</PopoverContent>
</Popover>
);
};

export default DatePicker;
16 changes: 10 additions & 6 deletions src/components/onboarding/company-form.tsx
Original file line number Diff line number Diff line change
@@ -32,10 +32,12 @@ import countries from "@/lib/countries";
import { cn, isFileExists, validateFile } from "@/lib/utils";
import { api } from "@/trpc/react";
import type { RouterOutputs } from "@/trpc/shared";
import { format, isValid, parse } from "date-fns";
import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
import { useRef, useState } from "react";
import { toast } from "sonner";
import DatePicker from "../common/date-picker";
import Loading from "../common/loading";
import { LinearCombobox } from "../ui/combobox";

@@ -73,9 +75,7 @@ export const CompanyForm = ({ type, data }: CompanyFormProps) => {
company: {
city: data?.company.city ?? "",
incorporationCountry: data?.company.incorporationCountry ?? "",
incorporationDate: data?.company.incorporationDate
? dayjsExt(data.company.incorporationDate).format("YYYY-MM-DD")
: "",
incorporationDate: data?.company.incorporationDate,
incorporationState: data?.company.incorporationState ?? "",
incorporationType: data?.company.incorporationType ?? "",
name: data?.company.name ?? "",
@@ -443,9 +443,13 @@ export const CompanyForm = ({ type, data }: CompanyFormProps) => {
render={({ field }) => (
<FormItem>
<FormLabel>Incorporation date</FormLabel>
<FormControl>
<Input type="date" {...field} />
</FormControl>
<div>
<DatePicker
dateFormat="YYYY-MM-DD"
onSelect={field.onChange}
selected={field.value}
/>
</div>
<FormMessage className="text-xs font-light" />
</FormItem>
)}
21 changes: 14 additions & 7 deletions src/components/securities/options/steps/relevant-dates.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import DatePicker from "@/components/common/date-picker";
import { Button } from "@/components/ui/button";
import {
Form,
@@ -21,11 +22,11 @@ import { useForm } from "react-hook-form";
import { z } from "zod";

const formSchema = z.object({
boardApprovalDate: z.string().date(),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to change the zod schemas form string() to date() because the component expected so. Would love to hear about that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be fine, you probably can coerce as well.

rule144Date: z.string().date(),
issueDate: z.string().date(),
expirationDate: z.string().date(),
vestingStartDate: z.string().date(),
boardApprovalDate: z.date(),
rule144Date: z.date(),
issueDate: z.date(),
expirationDate: z.date(),
vestingStartDate: z.date(),
});

type TFormSchema = z.infer<typeof formSchema>;
@@ -53,7 +54,10 @@ export const RelevantDates = () => {
<FormItem>
<FormLabel>Issue date</FormLabel>
<FormControl>
<Input type="date" {...field} />
<DatePicker
selected={field.value}
onSelect={field.onChange}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
@@ -67,7 +71,10 @@ export const RelevantDates = () => {
<FormItem>
<FormLabel>Expiry date</FormLabel>
<FormControl>
<Input type="date" {...field} />
<DatePicker
selected={field.value}
onSelect={field.onChange}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
30 changes: 21 additions & 9 deletions src/components/securities/shares/steps/relevant-dates.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import DatePicker from "@/components/common/date-picker";
import { Button } from "@/components/ui/button";
import {
Form,
@@ -9,7 +10,6 @@ import {
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import {
StepperModalFooter,
StepperPrev,
@@ -21,10 +21,10 @@ import { useForm } from "react-hook-form";
import { z } from "zod";

const formSchema = z.object({
boardApprovalDate: z.string().date(),
rule144Date: z.string().date(),
issueDate: z.string().date(),
vestingStartDate: z.string().date(),
boardApprovalDate: z.date(),
rule144Date: z.date(),
issueDate: z.date(),
vestingStartDate: z.date(),
});

type TFormSchema = z.infer<typeof formSchema>;
@@ -54,7 +54,10 @@ export const RelevantDates = () => {
<FormItem>
<FormLabel>Issue date</FormLabel>
<FormControl>
<Input type="date" {...field} />
<DatePicker
selected={field.value}
onSelect={field.onChange}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
@@ -69,7 +72,10 @@ export const RelevantDates = () => {
<FormItem>
<FormLabel>Vesting start date</FormLabel>
<FormControl>
<Input type="date" {...field} />
<DatePicker
selected={field.value}
onSelect={field.onChange}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
@@ -87,7 +93,10 @@ export const RelevantDates = () => {
<FormItem>
<FormLabel>Board approval date</FormLabel>
<FormControl>
<Input type="date" {...field} />
<DatePicker
selected={field.value}
onSelect={field.onChange}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
@@ -102,7 +111,10 @@ export const RelevantDates = () => {
<FormItem>
<FormLabel>Rule 144 date</FormLabel>
<FormControl>
<Input type="date" {...field} />
<DatePicker
selected={field.value}
onSelect={field.onChange}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
Loading
Loading