-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
270 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"use client"; | ||
|
||
import { Button } from "@midday/ui/button"; | ||
import { useFormContext } from "react-hook-form"; | ||
import type { InvoiceFormValues } from "./schema"; | ||
|
||
export function CreateButton() { | ||
const { handleSubmit } = useFormContext<InvoiceFormValues>(); | ||
|
||
const onSubmit = handleSubmit((data) => { | ||
// Handle form submission | ||
console.log(data); | ||
}); | ||
|
||
return <Button onClick={onSubmit}>Create</Button>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,42 @@ | ||
import { Calendar } from "@midday/ui/calendar"; | ||
import { Popover, PopoverContent, PopoverTrigger } from "@midday/ui/popover"; | ||
import { format } from "date-fns"; | ||
import { useState } from "react"; | ||
import { useFormContext } from "react-hook-form"; | ||
import { LabelInput } from "./label-input"; | ||
import type { InvoiceFormValues } from "./schema"; | ||
|
||
export function DueDate() { | ||
const { setValue, watch } = useFormContext<InvoiceFormValues>(); | ||
const dueDate = watch("dueDate"); | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const handleSelect = (date: Date | undefined) => { | ||
if (date) { | ||
setValue("dueDate", date, { shouldValidate: true }); | ||
setIsOpen(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="text-[11px] text-[#878787] font-mono"> | ||
Due date: <span className="text-primary">08/12/2024</span> | ||
<div className="flex space-x-1 items-center"> | ||
<div className="flex items-center"> | ||
<LabelInput name="settings.dueDate" /> | ||
<span className="text-[11px] text-[#878787] font-mono">:</span> | ||
</div> | ||
<Popover open={isOpen} onOpenChange={setIsOpen}> | ||
<PopoverTrigger className="text-primary text-[11px] font-mono whitespace-nowrap flex"> | ||
{format(dueDate || new Date(), "MM/dd/yyyy")} | ||
</PopoverTrigger> | ||
<PopoverContent className="w-auto p-0"> | ||
<Calendar | ||
mode="single" | ||
selected={dueDate} | ||
onSelect={handleSelect} | ||
initialFocus | ||
/> | ||
</PopoverContent> | ||
</Popover> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import { LabelInput } from "./label-input"; | ||
|
||
export function InvoiceNo() { | ||
return ( | ||
<div className="text-[11px] text-[#878787] font-mono"> | ||
Invoice NO: <span className="text-primary">INV-01</span> | ||
<div className="flex space-x-1 items-center"> | ||
<div className="flex items-center"> | ||
<LabelInput name="settings.invoiceNo" /> | ||
<span className="text-[11px] text-[#878787] font-mono">:</span> | ||
</div> | ||
<span className="text-primary text-[11px] font-mono whitespace-nowrap"> | ||
INV-01 | ||
</span> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,42 @@ | ||
import { Calendar } from "@midday/ui/calendar"; | ||
import { Popover, PopoverContent, PopoverTrigger } from "@midday/ui/popover"; | ||
import { format } from "date-fns"; | ||
import { useState } from "react"; | ||
import { useFormContext } from "react-hook-form"; | ||
import { LabelInput } from "./label-input"; | ||
import type { InvoiceFormValues } from "./schema"; | ||
|
||
export function IssueDate() { | ||
const { setValue, watch } = useFormContext<InvoiceFormValues>(); | ||
const issueDate = watch("issueDate"); | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const handleSelect = (date: Date | undefined) => { | ||
if (date) { | ||
setValue("issueDate", date, { shouldValidate: true }); | ||
setIsOpen(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="text-[11px] text-[#878787] font-mono"> | ||
Issue date: <span className="text-primary">08/12/2024</span> | ||
<div className="flex space-x-1 items-center"> | ||
<div className="flex items-center"> | ||
<LabelInput name="settings.issueDate" /> | ||
<span className="text-[11px] text-[#878787] font-mono">:</span> | ||
</div> | ||
<Popover open={isOpen} onOpenChange={setIsOpen}> | ||
<PopoverTrigger className="text-primary text-[11px] font-mono whitespace-nowrap flex"> | ||
{format(issueDate || new Date(), "MM/dd/yyyy")} | ||
</PopoverTrigger> | ||
<PopoverContent className="w-auto p-0"> | ||
<Calendar | ||
mode="single" | ||
selected={issueDate} | ||
onSelect={handleSelect} | ||
initialFocus | ||
/> | ||
</PopoverContent> | ||
</Popover> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use client"; | ||
|
||
import { cn } from "@midday/ui/cn"; | ||
import { useFormContext } from "react-hook-form"; | ||
|
||
type Props = { | ||
name: string; | ||
required?: boolean; | ||
className?: string; | ||
}; | ||
|
||
export function LabelInput({ name, className }: Props) { | ||
const { setValue, watch } = useFormContext(); | ||
const value = watch(name); | ||
|
||
return ( | ||
<span | ||
className={cn("text-[11px] text-[#878787] font-mono", className)} | ||
id={name} | ||
contentEditable | ||
suppressContentEditableWarning | ||
onBlur={(e) => { | ||
const newValue = e.currentTarget.textContent || ""; | ||
setValue(name, newValue, { shouldValidate: true }); | ||
}} | ||
> | ||
{value} | ||
</span> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,61 @@ | ||
"use client"; | ||
|
||
import { useUpload } from "@/hooks/use-upload"; | ||
import { Skeleton } from "@midday/ui/skeleton"; | ||
import { useToast } from "@midday/ui/use-toast"; | ||
import { useFormContext } from "react-hook-form"; | ||
import type { InvoiceFormValues } from "./schema"; | ||
|
||
export function Logo() { | ||
const { watch, setValue } = useFormContext<InvoiceFormValues>(); | ||
const logoUrl = watch("logoUrl"); | ||
const { uploadFile, isLoading } = useUpload(); | ||
const { toast } = useToast(); | ||
|
||
const handleUpload = async (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const file = event.target.files?.[0]; | ||
if (file) { | ||
try { | ||
const { url } = await uploadFile({ | ||
file, | ||
path: ["dd6a039e-d071-423a-9a4d-9ba71325d890", "invoice", file.name], | ||
bucket: "avatars", | ||
}); | ||
|
||
setValue("logoUrl", url, { shouldValidate: true }); | ||
} catch (error) { | ||
toast({ | ||
title: "Something went wrong, please try again.", | ||
variant: "error", | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="size-[78px] bg-[repeating-linear-gradient(-60deg,#DBDBDB,#DBDBDB_1px,background_1px,background_5px)] dark:bg-[repeating-linear-gradient(-60deg,#2C2C2C,#2C2C2C_1px,background_1px,background_5px)]" /> | ||
<div className="relative size-[78px]"> | ||
<label htmlFor="logo-upload" className="absolute inset-0"> | ||
{isLoading ? ( | ||
<Skeleton className="w-full h-full" /> | ||
) : logoUrl ? ( | ||
<img | ||
src={logoUrl} | ||
alt="Invoice logo" | ||
className="w-full h-full object-cover" | ||
/> | ||
) : ( | ||
<div className="size-[78px] bg-[repeating-linear-gradient(-60deg,#DBDBDB,#DBDBDB_1px,background_1px,background_5px)] dark:bg-[repeating-linear-gradient(-60deg,#2C2C2C,#2C2C2C_1px,background_1px,background_5px)]" /> | ||
)} | ||
</label> | ||
|
||
<input | ||
id="logo-upload" | ||
type="file" | ||
accept="image/*" | ||
className="hidden" | ||
onChange={handleUpload} | ||
disabled={isLoading} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.