Skip to content

Commit

Permalink
Implemented days older than feature for item filtering on Admin side
Browse files Browse the repository at this point in the history
Need to update design to integrate both days older and days since
features
  • Loading branch information
axgu committed Nov 16, 2024
1 parent 23d602d commit 68f2a61
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const ItemSearchSchema = z.object({
query: z.string(),
color: z.nativeEnum(Color).nullable(),
status: z.nativeEnum(Status).nullable(),
value: z.nativeEnum(Value).nullable()
value: z.nativeEnum(Value).nullable(),
days: z.string()
});

export const UserSchema = z.object({
Expand Down
22 changes: 20 additions & 2 deletions src/pages/manage/items/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const Manage: NextPageWithLayout = () => {
query: '',
status: null,
color: null,
value: null
value: null,
days: ''
}
});
const items = trpc.item.search.useQuery(methods.getValues());
Expand Down Expand Up @@ -137,6 +138,22 @@ const Manage: NextPageWithLayout = () => {
/>
</div>
</div>

<div className="flex w-full items-center justify-between p-4">
<div className="font-bold">Date</div>
<div className="w-48">
<input
type="text"
placeholder="90"
className="input-bordered input input-sm w-full"
{...methods.register('days')}
/>
<label className="text-xs text-error">
{methods.formState.errors.days?.message}
</label>
</div>
</div>

<div className="flex w-full items-center justify-end gap-2 p-4">
<button
className="btn-ghost btn-sm btn"
Expand Down Expand Up @@ -255,7 +272,8 @@ const Manage: NextPageWithLayout = () => {
query: methods.watch('query'),
status: methods.watch('status'),
color: methods.watch('color'),
value: methods.watch('value')
value: methods.watch('value'),
days: methods.watch('days')
}}
/>
</>
Expand Down
8 changes: 7 additions & 1 deletion src/server/trpc/router/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ export default router({
},
color: input.color ?? undefined,
status: input.status ?? undefined,
value: input.value ?? undefined
value: input.value ?? undefined,

createdAt: {
lte: input.days
? new Date(Date.now() - parseInt(input.days) * 24 * 60 * 60 * 1000)
: new Date(Date.now())
}
}
})
),
Expand Down

0 comments on commit 68f2a61

Please sign in to comment.