fix: date picker improvements (#793)

* use vue component for date picker

* zero out database fields even when set to 0001-xx-xx

* fix wrong datetime display + improved datepicker

* fix ts error

* zero out times

* add date-fns to dependencies
This commit is contained in:
Hayden 2024-02-29 12:58:26 -06:00 committed by GitHub
parent c708b1759e
commit 4c9ddac395
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 186 additions and 41 deletions

View file

@ -799,8 +799,11 @@ func (e *ItemsRepository) ZeroOutTimeFields(ctx context.Context, GID uuid.UUID)
item.HasGroupWith(group.ID(GID)),
item.Or(
item.PurchaseTimeNotNil(),
item.PurchaseFromLT("0002-01-01"),
item.SoldTimeNotNil(),
item.SoldToLT("0002-01-01"),
item.WarrantyExpiresNotNil(),
item.WarrantyDetailsLT("0002-01-01"),
),
)
@ -819,15 +822,36 @@ func (e *ItemsRepository) ZeroOutTimeFields(ctx context.Context, GID uuid.UUID)
updateQ := e.db.Item.Update().Where(item.ID(i.ID))
if !i.PurchaseTime.IsZero() {
updateQ.SetPurchaseTime(toDateOnly(i.PurchaseTime))
switch {
case i.PurchaseTime.Year() < 100:
updateQ.ClearPurchaseTime()
default:
updateQ.SetPurchaseTime(toDateOnly(i.PurchaseTime))
}
} else {
updateQ.ClearPurchaseTime()
}
if !i.SoldTime.IsZero() {
updateQ.SetSoldTime(toDateOnly(i.SoldTime))
switch {
case i.SoldTime.Year() < 100:
updateQ.ClearSoldTime()
default:
updateQ.SetSoldTime(toDateOnly(i.SoldTime))
}
} else {
updateQ.ClearSoldTime()
}
if !i.WarrantyExpires.IsZero() {
updateQ.SetWarrantyExpires(toDateOnly(i.WarrantyExpires))
switch {
case i.WarrantyExpires.Year() < 100:
updateQ.ClearWarrantyExpires()
default:
updateQ.SetWarrantyExpires(toDateOnly(i.WarrantyExpires))
}
} else {
updateQ.ClearWarrantyExpires()
}
_, err = updateQ.Save(ctx)
@ -879,7 +903,6 @@ func (e *ItemsRepository) SetPrimaryPhotos(ctx context.Context, GID uuid.UUID) (
_, err = e.db.Attachment.UpdateOne(a).
SetPrimary(true).
Save(ctx)
if err != nil {
return updated, err
}