feat: enhance date formatting in AdminUserView for improved readability and consistency

This commit is contained in:
2026-01-20 22:51:44 -06:00
parent 264ee860df
commit 8ea486a4f4

View File

@@ -30,12 +30,39 @@ const AdminUserView = () => {
const fileInputRef = useRef(null); const fileInputRef = useRef(null);
const [changeRoleDialogOpen, setChangeRoleDialogOpen] = useState(false); const [changeRoleDialogOpen, setChangeRoleDialogOpen] = useState(false);
const formatLocalDateInputValue = (date) => {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
};
const formatDateInputValue = (value) => { const formatDateInputValue = (value) => {
if (!value) return ''; if (!value) return '';
if (typeof value === 'string') { if (typeof value === 'string') {
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
return value;
}
const parsed = new Date(value);
if (Number.isNaN(parsed.getTime())) {
return value.slice(0, 10); return value.slice(0, 10);
} }
return new Date(value).toISOString().slice(0, 10); return formatLocalDateInputValue(parsed);
}
const parsed = new Date(value);
if (Number.isNaN(parsed.getTime())) return '';
return formatLocalDateInputValue(parsed);
};
const formatDateDisplayValue = (value) => {
if (!value) return 'N/A';
if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value)) {
const [year, month, day] = value.split('-').map(Number);
return new Date(year, month - 1, day).toLocaleDateString();
}
const parsed = new Date(value);
if (Number.isNaN(parsed.getTime())) return 'N/A';
return parsed.toLocaleDateString();
}; };
useEffect(() => { useEffect(() => {
@@ -304,7 +331,7 @@ const AdminUserView = () => {
</div> </div>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Calendar className="h-4 w-4" /> <Calendar className="h-4 w-4" />
<span>Joined {joinedDate ? new Date(joinedDate).toLocaleDateString() : 'N/A'}</span> <span>Joined {formatDateDisplayValue(joinedDate)}</span>
</div> </div>
</div> </div>
</div> </div>
@@ -401,7 +428,7 @@ const AdminUserView = () => {
<div> <div>
<label className="text-sm font-medium text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Date of Birth</label> <label className="text-sm font-medium text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Date of Birth</label>
<p className="text-[var(--purple-ink)] mt-1" style={{ fontFamily: "'Nunito Sans', sans-serif" }}> <p className="text-[var(--purple-ink)] mt-1" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
{new Date(user.date_of_birth).toLocaleDateString()} {formatDateDisplayValue(user.date_of_birth)}
</p> </p>
</div> </div>
@@ -492,14 +519,14 @@ const AdminUserView = () => {
<div> <div>
<label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Start Date</label> <label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Start Date</label>
<p className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}> <p className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
{new Date(sub.start_date).toLocaleDateString()} {formatDateDisplayValue(sub.start_date)}
</p> </p>
</div> </div>
{sub.end_date && ( {sub.end_date && (
<div> <div>
<label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>End Date</label> <label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>End Date</label>
<p className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}> <p className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
{new Date(sub.end_date).toLocaleDateString()} {formatDateDisplayValue(sub.end_date)}
</p> </p>
</div> </div>
)} )}