Files
Junaid d0757a25ac refactor: Improve CreateChannelFromURL and CreateShopFromURL components for better readability and maintainability
- Enhanced conditional checks and removed unnecessary console logs.
- Updated capitalization for "Openfront" in various components.
- Improved handling of URL parameters after successful channel/shop creation.
- Refactored badge components to use a consistent style across PlatformTabs, StatusTabs, and MatchesTabs.
- Added delete functionality with confirmation dialog in OrderDetailsComponent.
- Enhanced logging in createShop action for better debugging.
2025-09-01 13:05:59 -07:00

134 lines
3.6 KiB
TypeScript

"use client";
import * as React from "react";
import { format } from "date-fns";
import { CalendarIcon } from "lucide-react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
interface DateTimePickerProps {
value?: string;
onChange?: (value: string) => void;
placeholder?: string;
className?: string;
disabled?: boolean;
}
export function DateTimePicker({
value,
onChange,
placeholder = "Pick a date and time",
className,
disabled = false,
}: DateTimePickerProps) {
const [date, setDate] = React.useState<Date | undefined>(
value ? new Date(value) : undefined
);
const [time, setTime] = React.useState<string>(
value ? format(new Date(value), "HH:mm") : ""
);
const [open, setOpen] = React.useState(false);
const handleDateSelect = (selectedDate: Date | undefined) => {
if (selectedDate) {
const newDate = new Date(selectedDate);
if (time) {
const [hours, minutes] = time.split(":");
newDate.setHours(parseInt(hours), parseInt(minutes));
}
setDate(newDate);
const isoString = newDate.toISOString().slice(0, 16); // YYYY-MM-DDTHH:mm format
onChange?.(isoString);
}
};
const handleTimeChange = (newTime: string) => {
setTime(newTime);
if (date && newTime) {
const [hours, minutes] = newTime.split(":");
const newDate = new Date(date);
newDate.setHours(parseInt(hours), parseInt(minutes));
setDate(newDate);
const isoString = newDate.toISOString().slice(0, 16); // YYYY-MM-DDTHH:mm format
onChange?.(isoString);
}
};
const handleClear = () => {
setDate(undefined);
setTime("");
onChange?.("");
setOpen(false);
};
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
variant="outline"
className={cn(
"w-full justify-start text-left font-normal",
!date && "text-muted-foreground",
className
)}
disabled={disabled}
>
<CalendarIcon className="mr-2 h-4 w-4" />
{date ? (
format(date, "PPP 'at' HH:mm")
) : (
<span>{placeholder}</span>
)}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<div className="p-3 space-y-3">
<Calendar
mode="single"
selected={date}
onSelect={handleDateSelect}
initialFocus
/>
<div className="space-y-2">
<Label htmlFor="time-input" className="text-sm font-medium">
Time
</Label>
<Input
id="time-input"
type="time"
value={time}
onChange={(e) => handleTimeChange(e.target.value)}
className="w-full"
/>
</div>
<div className="flex gap-2 pt-2">
<Button
variant="outline"
size="sm"
onClick={handleClear}
className="flex-1"
>
Clear
</Button>
<Button
size="sm"
onClick={() => setOpen(false)}
className="flex-1"
>
Done
</Button>
</div>
</div>
</PopoverContent>
</Popover>
);
}