chore: date time attribute

This commit is contained in:
Aaryan Khandelwal 2023-09-18 21:33:27 +05:30
parent 2169ba35a9
commit a014564d11
9 changed files with 57 additions and 68 deletions

View File

@ -1,44 +1,41 @@
import { useState } from "react"; // react-datepicker
import ReactDatePicker from "react-datepicker";
// types // types
import { Props } from "./types"; import { Props } from "./types";
import { renderDateFormat } from "helpers/date-time.helper";
const DATE_FORMATS: { [key: string]: string } = {
"MM-DD-YYYY": "MM-dd-yyyy",
"DD-MM-YYYY": "dd-MM-yyyy",
"YYYY-MM-DD": "yyyy-MM-dd",
};
const TIME_FORMATS: { [key: string]: string } = {
"12": "hh:mm aa",
"24": "HH:mm",
};
export const CustomDateTimeAttribute: React.FC<Props & { value: Date | undefined }> = ({ export const CustomDateTimeAttribute: React.FC<Props & { value: Date | undefined }> = ({
attributeDetails,
onChange, onChange,
value, value,
}) => { }) => (
const [isEditing, setIsEditing] = useState(false); <div className="flex-shrink-0">
<ReactDatePicker
const handleUpdateDateTime = (val: string) => { selected={value}
setIsEditing(false); onChange={onChange}
className="bg-custom-background-80 rounded text-xs px-2.5 py-0.5 outline-none"
onChange(new Date(val)); calendarClassName="!bg-custom-background-80"
}; dateFormat={`${
attributeDetails.extra_settings.hide_date
return ( ? ""
<div className="flex-shrink-0"> : DATE_FORMATS[attributeDetails.extra_settings.date_format] ?? "dd-MM-yyyy"
{!isEditing && }${
(value ? ( attributeDetails.extra_settings.hide_time
<div ? ""
className="cursor-pointer text-xs px-2 py-0.5 bg-custom-background-80 rounded w-min max-w-full whitespace-nowrap outline-none" : ", " + (TIME_FORMATS[attributeDetails.extra_settings.time_format] ?? "HH:mm")
onClick={() => setIsEditing(true)} }`}
> showTimeInput={!attributeDetails.extra_settings.hide_time}
{renderDateFormat(value)} isClearable={!attributeDetails.is_required}
</div> />
) : ( </div>
<div className="cursor-pointer text-xs truncate" onClick={() => setIsEditing(true)}> );
Empty
</div>
))}
{isEditing && (
<input
type="datetime-local"
className="text-xs px-2 py-0.5 bg-custom-background-80 rounded w-full outline-none"
defaultValue={value?.toString()}
onBlur={(e) => handleUpdateDateTime(e.target.value)}
/>
)}
</div>
);
};

View File

@ -45,11 +45,8 @@ export const CustomEmailAttribute: React.FC<Props & { value: string | undefined
return ( return (
<div className="flex-shrink-0"> <div className="flex-shrink-0">
{!isEditing && ( {!isEditing && (
<div <div className="cursor-pointer text-xs truncate" onClick={() => setIsEditing(true)}>
className="cursor-pointer text-xs truncate bg-custom-background-80 px-2.5 py-0.5 rounded" {value && value !== "" ? value : "Empty"}
onClick={() => setIsEditing(true)}
>
{value && value !== "" ? value : `Enter ${attributeDetails.display_name}`}
</div> </div>
)} )}
{isEditing && ( {isEditing && (

View File

@ -107,21 +107,19 @@ export const CustomFileAttribute: React.FC<Props & { value: string | undefined }
)} )}
<div <div
{...getRootProps()} {...getRootProps()}
className={`flex items-center justify-center bg-custom-background-80 text-xs rounded px-2.5 py-0.5 cursor-pointer ${ className={`flex items-center bg-custom-background-80 text-xs rounded px-2.5 py-0.5 cursor-pointer truncate w-min max-w-full whitespace-nowrap ${
isDragActive ? "bg-custom-primary-100/10" : "" isDragActive ? "bg-custom-primary-100/10" : ""
} ${isDragReject ? "bg-red-500/10" : ""}`} } ${isDragReject ? "bg-red-500/10" : ""}`}
> >
<input {...getInputProps()} /> <input className="flex-shrink-0" {...getInputProps()} />
<span className=""> <span className={`flex-grow truncate text-left ${fileError ? "text-red-500" : ""}`}>
{isDragActive ? ( {isDragActive
<p>Drop here...</p> ? "Drop here..."
) : fileError ? ( : fileError
<p className="text-red-500">{fileError}</p> ? fileError
) : isUploading ? ( : isUploading
<p>Uploading...</p> ? "Uploading..."
) : ( : `Upload ${value && value !== "" ? "new " : ""}file`}
<p>Upload {value && value !== "" ? "new " : ""}file</p>
)}
</span> </span>
</div> </div>
</div> </div>

View File

@ -49,7 +49,7 @@ export const CustomNumberAttribute: React.FC<Props & { value: number | undefined
return ( return (
<div className="flex-shrink-0"> <div className="flex-shrink-0">
{!isEditing && ( {!isEditing && (
<div className="cursor-pointer text-xs" onClick={() => setIsEditing(true)}> <div className="cursor-pointer text-xs truncate flex" onClick={() => setIsEditing(true)}>
{value ? ( {value ? (
<> <>
{extraSettings?.representation === "bar" ? ( {extraSettings?.representation === "bar" ? (
@ -79,12 +79,12 @@ export const CustomNumberAttribute: React.FC<Props & { value: number | undefined
/> />
</div> </div>
) : ( ) : (
<span className="font-medium">{value}</span> <span className="font-medium truncate">{value}</span>
)} )}
</> </>
) : ( ) : (
<div <div
className="cursor-pointer text-xs truncate bg-custom-background-80 px-2.5 py-0.5 rounded" className="cursor-pointer text-xs truncate bg-custom-background-80 px-2.5 py-0.5 rounded w-min whitespace-nowrap flex-grow"
onClick={() => setIsEditing(true)} onClick={() => setIsEditing(true)}
> >
{value ?? `Enter ${attributeDetails.display_name}`} {value ?? `Enter ${attributeDetails.display_name}`}

View File

@ -45,10 +45,7 @@ export const CustomTextAttribute: React.FC<Props & { value: string | undefined }
return ( return (
<div className="flex-shrink-0"> <div className="flex-shrink-0">
{!isEditing && ( {!isEditing && (
<div <div className="cursor-pointer text-xs truncate" onClick={() => setIsEditing(true)}>
className="cursor-pointer text-xs truncate bg-custom-background-80 px-2.5 py-0.5 rounded"
onClick={() => setIsEditing(true)}
>
{value && value !== "" ? value : `Enter ${attributeDetails.display_name}`} {value && value !== "" ? value : `Enter ${attributeDetails.display_name}`}
</div> </div>
)} )}

View File

@ -43,10 +43,7 @@ export const CustomUrlAttribute: React.FC<Props & { value: string | undefined }>
return ( return (
<div className="flex-shrink-0"> <div className="flex-shrink-0">
{!isEditing && ( {!isEditing && (
<div <div className="cursor-pointer text-xs truncate" onClick={() => setIsEditing(true)}>
className="cursor-pointer text-xs truncate bg-custom-background-80 px-2.5 py-0.5 rounded"
onClick={() => setIsEditing(true)}
>
{value && value !== "" ? value : `Enter ${attributeDetails.display_name}`} {value && value !== "" ? value : `Enter ${attributeDetails.display_name}`}
</div> </div>
)} )}

View File

@ -120,7 +120,7 @@ export const SidebarCustomAttributesList: React.FC<Props> = observer(({ issue })
<CustomDateTimeAttribute <CustomDateTimeAttribute
attributeDetails={attribute} attributeDetails={attribute}
issueId={issue.id} issueId={issue.id}
onChange={(val: string) => handleAttributeUpdate(attribute.id, [val])} onChange={(val: Date) => handleAttributeUpdate(attribute.id, [val.toISOString()])}
projectId={issue.project} projectId={issue.project}
value={attributeValue ? new Date(attributeValue?.[0]?.value ?? "") : undefined} value={attributeValue ? new Date(attributeValue?.[0]?.value ?? "") : undefined}
/> />

View File

@ -46,6 +46,8 @@ export const CUSTOM_ATTRIBUTES_LIST: {
display_name: "", display_name: "",
extra_settings: { extra_settings: {
date_format: "DD-MM-YYYY", date_format: "DD-MM-YYYY",
hide_date: false,
hide_time: false,
time_format: "12", time_format: "12",
}, },
is_required: false, is_required: false,

View File

@ -29,7 +29,8 @@
.react-datepicker { .react-datepicker {
font-family: "Inter" !important; font-family: "Inter" !important;
background-color: rgba(var(--color-background-100)) !important; background-color: rgba(var(--color-background-100)) !important;
border: 1px solid rgba(var(--color-background-80)) !important; border: 1px solid rgba(var(--color-border-200)) !important;
box-shadow: var(--color-shadow-xs);
} }
.react-datepicker__month-container { .react-datepicker__month-container {