mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
Add timestamps to activity logs
Require a date and time when creating activity logs, allow minute-level selection, and improve date-picker scrolling within dialogs.
This commit is contained in:
+19
-1
@@ -16,6 +16,8 @@ import {
|
||||
} from '@/components/ui/select';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { FilePlus2, Loader2, Save } from 'lucide-react';
|
||||
import { DateTimePicker } from '@/components/ui/date-time-picker';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export interface IActivityLogType {
|
||||
id: number;
|
||||
@@ -52,6 +54,7 @@ export default function AddActivityLogModal({
|
||||
const router = useRouter();
|
||||
const [selectedTypeId, setSelectedTypeId] = useState<string>('13');
|
||||
const [description, setDescription] = useState<string>('');
|
||||
const [date, setDate] = useState<Date | undefined>();
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const { data: fetchedData, isLoading: isLoadingTypes } = useFetchWithAxios(open ? '/project-assignment-status?type=log' : null);
|
||||
@@ -88,6 +91,7 @@ export default function AddActivityLogModal({
|
||||
|
||||
const typeName = activeType?.name || 'update';
|
||||
const payload = {
|
||||
date_at: dayjs(date).format('YYYY-MM-DD HH:mm:ss'),
|
||||
project_assignment_id: Number(assignmentId),
|
||||
type: typeName,
|
||||
description: description.trim(),
|
||||
@@ -142,6 +146,20 @@ export default function AddActivityLogModal({
|
||||
|
||||
{/* Form Body */}
|
||||
<form onSubmit={handleSubmit} className="space-y-5 px-6 pb-5 pt-0">
|
||||
{/* Description Field */}
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label htmlFor="log-description" className="text-xs font-semibold text-foreground">
|
||||
Datetime <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
</div>
|
||||
<DateTimePicker
|
||||
placeholder="Pilih tanggal selesai"
|
||||
date={date}
|
||||
setDate={setDate}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Activity Type Field with Badge */}
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
@@ -222,7 +240,7 @@ export default function AddActivityLogModal({
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={isSubmitting || !description.trim()}
|
||||
disabled={isSubmitting || !description.trim() || !date}
|
||||
className="text-xs gap-1.5 bg-his hover:bg-his/90 text-white font-medium shadow-md shadow-his/20"
|
||||
>
|
||||
{isSubmitting ? (
|
||||
|
||||
@@ -204,7 +204,7 @@ function CalendarDayButton({
|
||||
data-range-end={modifiers.range_end}
|
||||
data-range-middle={modifiers.range_middle}
|
||||
className={cn(
|
||||
"data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 dark:hover:text-accent-foreground flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70",
|
||||
"data-[selected-single=true]:bg-his data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-his data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-his data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 dark:hover:text-accent-foreground flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70",
|
||||
defaultClassNames.day,
|
||||
className
|
||||
)}
|
||||
|
||||
@@ -28,7 +28,7 @@ export function DateTimePicker({ date, setDate, placeholder, disabled, disabledD
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const hours = Array.from({ length: 24 }, (_, i) => i).reverse();
|
||||
const minutes = Array.from({ length: 12 }, (_, i) => i * 5);
|
||||
const minutes = Array.from({ length: 60 }, (_, i) => i * 1);
|
||||
|
||||
const parsedDate = useMemo(() => {
|
||||
if (!date) return undefined;
|
||||
@@ -78,7 +78,11 @@ export function DateTimePicker({ date, setDate, placeholder, disabled, disabledD
|
||||
}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-auto p-0">
|
||||
<PopoverContent
|
||||
className="w-auto p-0"
|
||||
onWheel={(e) => e.stopPropagation()}
|
||||
onTouchMove={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="sm:flex">
|
||||
<Calendar
|
||||
mode="single"
|
||||
@@ -90,8 +94,8 @@ export function DateTimePicker({ date, setDate, placeholder, disabled, disabledD
|
||||
initialFocus
|
||||
endMonth={new Date(2050, 11)}
|
||||
/>
|
||||
<div className="flex flex-col sm:flex-row sm:h-[300px] divide-y sm:divide-y-0 sm:divide-x">
|
||||
<ScrollArea className="w-64 sm:w-auto">
|
||||
<div className="flex flex-col sm:flex-row sm:h-75 divide-y sm:divide-y-0 sm:divide-x">
|
||||
<ScrollArea className="w-64 sm:w-auto sm:h-full">
|
||||
<div className="flex sm:flex-col p-2">
|
||||
{hours.map((hour) => (
|
||||
<Button
|
||||
@@ -108,7 +112,7 @@ export function DateTimePicker({ date, setDate, placeholder, disabled, disabledD
|
||||
</div>
|
||||
<ScrollBar orientation="horizontal" className="sm:hidden" />
|
||||
</ScrollArea>
|
||||
<ScrollArea className="w-64 sm:w-auto">
|
||||
<ScrollArea className="w-64 sm:w-auto sm:h-full">
|
||||
<div className="flex sm:flex-col p-2">
|
||||
{minutes.map((minute) => (
|
||||
<Button
|
||||
|
||||
@@ -8,19 +8,89 @@ export interface AdditionalProps extends React.ComponentPropsWithoutRef<typeof S
|
||||
height?: string
|
||||
}
|
||||
|
||||
function ScrollArea({
|
||||
className,
|
||||
children,
|
||||
height,
|
||||
...props
|
||||
}: AdditionalProps) {
|
||||
const ScrollArea = React.forwardRef<
|
||||
React.ComponentRef<typeof ScrollAreaPrimitive.Root>,
|
||||
AdditionalProps
|
||||
>(({ className, children, height, ...props }, ref) => {
|
||||
const viewportRef = React.useRef<HTMLDivElement>(null)
|
||||
|
||||
React.useEffect(() => {
|
||||
const viewport = viewportRef.current
|
||||
if (!viewport) return
|
||||
|
||||
const handleWheel = (e: WheelEvent) => {
|
||||
const canScrollY = viewport.scrollHeight > viewport.clientHeight
|
||||
const canScrollX = viewport.scrollWidth > viewport.clientWidth
|
||||
|
||||
if (!canScrollY && !canScrollX) return
|
||||
|
||||
let deltaY = e.deltaY
|
||||
let deltaX = e.deltaX
|
||||
|
||||
if (e.deltaMode === 1) {
|
||||
// DOM_DELTA_LINE (Firefox default)
|
||||
deltaY *= 16
|
||||
deltaX *= 16
|
||||
} else if (e.deltaMode === 2) {
|
||||
// DOM_DELTA_PAGE
|
||||
deltaY *= viewport.clientHeight
|
||||
deltaX *= viewport.clientWidth
|
||||
}
|
||||
|
||||
let scrolled = false
|
||||
|
||||
if (canScrollY && Math.abs(deltaY) > 0) {
|
||||
const prev = viewport.scrollTop
|
||||
viewport.scrollTop += deltaY
|
||||
if (viewport.scrollTop !== prev) {
|
||||
scrolled = true
|
||||
}
|
||||
}
|
||||
|
||||
if (canScrollX && Math.abs(deltaX) > 0) {
|
||||
const prev = viewport.scrollLeft
|
||||
viewport.scrollLeft += deltaX
|
||||
if (viewport.scrollLeft !== prev) {
|
||||
scrolled = true
|
||||
}
|
||||
} else if (!canScrollY && canScrollX && Math.abs(deltaY) > 0) {
|
||||
// Map vertical wheel to horizontal scroll if container is only horizontally scrollable
|
||||
const prev = viewport.scrollLeft
|
||||
viewport.scrollLeft += deltaY
|
||||
if (viewport.scrollLeft !== prev) {
|
||||
scrolled = true
|
||||
}
|
||||
}
|
||||
|
||||
if (scrolled) {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
const handleTouchMove = (e: TouchEvent) => {
|
||||
// Prevent parent scroll-lock (e.g. react-remove-scroll in Radix Dialog) from cancelling touch scroll inside viewport
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
viewport.addEventListener("wheel", handleWheel, { passive: false })
|
||||
viewport.addEventListener("touchmove", handleTouchMove, { passive: true })
|
||||
|
||||
return () => {
|
||||
viewport.removeEventListener("wheel", handleWheel)
|
||||
viewport.removeEventListener("touchmove", handleTouchMove)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<ScrollAreaPrimitive.Root
|
||||
ref={ref}
|
||||
data-slot="scroll-area"
|
||||
className={cn("relative", className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport
|
||||
ref={viewportRef}
|
||||
data-slot="scroll-area-viewport"
|
||||
className={`focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1 ${height || 'h-full'}`}
|
||||
>
|
||||
@@ -30,7 +100,8 @@ function ScrollArea({
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
)
|
||||
}
|
||||
})
|
||||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
|
||||
|
||||
function ScrollBar({
|
||||
className,
|
||||
|
||||
Reference in New Issue
Block a user