fix: relative date for birthday
Signed-off-by: Varun Raj <mailme@varunraj.in>
This commit is contained in:
1 parent
e8a3d50e11
commit
7fdb42137c
8 files changed
+45
-13
No files matched your search
@@ -31,6 +31,7 @@
|
|||||||
"@types/cookie": "^0.6.0",
|
"@types/cookie": "^0.6.0",
|
||||||
"@types/qs": "^6.9.15",
|
"@types/qs": "^6.9.15",
|
||||||
"axios": "^1.7.4",
|
"axios": "^1.7.4",
|
||||||
|
"chrono-node": "^1.4.9",
|
||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"cmdk": "1.0.0",
|
"cmdk": "1.0.0",
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export default function PeopleList() {
|
|||||||
if (errorMessage) return <div>{errorMessage}</div>;
|
if (errorMessage) return <div>{errorMessage}</div>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-6 gap-1 p-2">
|
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-5 gap-1 p-2">
|
||||||
{people.map((person) => (
|
{people.map((person) => (
|
||||||
<PersonItem person={person} key={person.id} onRemove={handleRemove}/>
|
<PersonItem person={person} key={person.id} onRemove={handleRemove}/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ import React, { useState } from 'react'
|
|||||||
import { DatePicker } from '../ui/datepicker'
|
import { DatePicker } from '../ui/datepicker'
|
||||||
import { updatePerson } from '@/handlers/api/people.handler';
|
import { updatePerson } from '@/handlers/api/people.handler';
|
||||||
import { formatDate } from '@/helpers/date.helper';
|
import { formatDate } from '@/helpers/date.helper';
|
||||||
|
import { Input } from '../ui/input';
|
||||||
|
import { useToast } from '../ui/use-toast';
|
||||||
|
// @ts-ignore
|
||||||
|
import chrono from 'chrono-node'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
person: IPerson
|
person: IPerson
|
||||||
@@ -11,19 +17,22 @@ interface IProps {
|
|||||||
export default function PersonBirthdayCell(
|
export default function PersonBirthdayCell(
|
||||||
{ person }: IProps
|
{ person }: IProps
|
||||||
) {
|
) {
|
||||||
const [formData, setFormData] = useState(person);
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const { toast } = useToast();
|
||||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||||
|
const [textDate, setTextDate] = useState<string | null>(person.birthDate ? formatDate(person.birthDate?.toString(), 'PPP'): "");
|
||||||
|
|
||||||
const handleEdit = (date?: Date | null) => {
|
const handleEdit = (date?: Date | null) => {
|
||||||
if (!date) return;
|
const formatedDate = date ? formatDate(date.toString(), 'yyyy-MM-dd') : null;
|
||||||
const formatedDate = formatDate(date.toString(), 'yyyy-MM-dd');
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
return updatePerson(person.id, {
|
return updatePerson(person.id, {
|
||||||
birthDate: formatedDate,
|
birthDate: formatedDate,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
toast({
|
||||||
|
title: "Success",
|
||||||
|
description: "Person updated successfully",
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
@@ -33,5 +42,27 @@ export default function PersonBirthdayCell(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return <DatePicker date={person.birthDate} onSelect={handleEdit}/>
|
return (
|
||||||
|
<div className='flex gap-1'>
|
||||||
|
<Input
|
||||||
|
className=''
|
||||||
|
value={textDate || ""}
|
||||||
|
placeholder='Enter a date'
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
const parsedDate = chrono.parseDate(textDate || "");
|
||||||
|
if (parsedDate) {
|
||||||
|
handleEdit(parsedDate);
|
||||||
|
setTextDate(formatDate(parsedDate.toString(), 'PPP'));
|
||||||
|
} else {
|
||||||
|
handleEdit(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={loading}
|
||||||
|
onChange={(e) => setTextDate(e.target.value)}
|
||||||
|
/>
|
||||||
|
<DatePicker date={person.birthDate} onSelect={handleEdit} iconOnly/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ export default function PersonItem({ person, onRemove }: IProps) {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Avatar
|
<Avatar
|
||||||
className="w-full h-auto rounded-lg"
|
className="w-full min-h-full h-auto rounded-lg"
|
||||||
src={person.thumbnailPath}
|
src={person.thumbnailPath}
|
||||||
alt={person.name}
|
alt={person.name}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ import {
|
|||||||
interface IProps {
|
interface IProps {
|
||||||
date?: Date | null
|
date?: Date | null
|
||||||
onSelect?: (date?: Date | null) => any
|
onSelect?: (date?: Date | null) => any
|
||||||
|
iconOnly?: boolean
|
||||||
}
|
}
|
||||||
export function DatePicker(
|
export function DatePicker(
|
||||||
{ date: _date, onSelect }: IProps
|
{ date: _date, onSelect, iconOnly }: IProps
|
||||||
) {
|
) {
|
||||||
const [date, setDate] = React.useState<Date | null>(_date || null)
|
const [date, setDate] = React.useState<Date | null>(_date || null)
|
||||||
|
|
||||||
@@ -32,12 +33,12 @@ export function DatePicker(
|
|||||||
<Button
|
<Button
|
||||||
variant={"outline"}
|
variant={"outline"}
|
||||||
className={cn(
|
className={cn(
|
||||||
"justify-start text-left font-normal",
|
"justify-start text-left font-normal flex gap-1",
|
||||||
!date && "text-muted-foreground"
|
!date && "text-muted-foreground"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<CalendarIcon className="mr-2 h-4 w-4" />
|
<CalendarIcon className="h-3 w-3" />
|
||||||
{date ? format(date, "PPP") : <span>Pick a date</span>}
|
{!iconOnly && <span>{date ? format(date, "PPP") : <span>Pick a date</span>}</span>}
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-auto p-0">
|
<PopoverContent className="w-auto p-0">
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export const listPeople = (filters: IPersonListFilters): Promise<IPeopleListResp
|
|||||||
|
|
||||||
export const updatePerson = (id: string, data: Partial<{
|
export const updatePerson = (id: string, data: Partial<{
|
||||||
name: string;
|
name: string;
|
||||||
birthDate: string;
|
birthDate: string | null;
|
||||||
isHidden: boolean;
|
isHidden: boolean;
|
||||||
}>) => {
|
}>) => {
|
||||||
return API.put(UPDATE_PERSON_PATH(id), data)
|
return API.put(UPDATE_PERSON_PATH(id), data)
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ export default function MissingLocations() {
|
|||||||
leftComponent="Missing Location"
|
leftComponent="Missing Location"
|
||||||
rightComponent={
|
rightComponent={
|
||||||
<>
|
<>
|
||||||
<AssetFilter />
|
|
||||||
<Badge variant={"outline"}>
|
<Badge variant={"outline"}>
|
||||||
{config.selectedIds.length} Selected
|
{config.selectedIds.length} Selected
|
||||||
</Badge>
|
</Badge>
|
||||||
|
|||||||
Reference in new issue
Block a user