From 19adcea5094d4750b3c28ce065c012486883d320 Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Sun, 11 Feb 2024 09:23:45 +0100 Subject: [PATCH] chore: refactor code --- src/components/expenses/ExpensesForm.tsx | 8 +++++--- src/components/expenses/SetTagForm.tsx | 4 ++-- src/components/hours/HoursForm.tsx | 6 +++--- src/components/income/IncomeForm.tsx | 7 ++++--- src/components/subscriptions/SubscriptionForm.tsx | 6 +++--- src/pages/income.tsx | 4 ++-- src/pages/subscriptions.tsx | 4 ++-- src/server/routers/expenses.ts | 1 + src/server/routers/income.ts | 6 ++++-- 9 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/components/expenses/ExpensesForm.tsx b/src/components/expenses/ExpensesForm.tsx index 5e54816..1cc4870 100644 --- a/src/components/expenses/ExpensesForm.tsx +++ b/src/components/expenses/ExpensesForm.tsx @@ -26,16 +26,16 @@ interface Props { } export function ExpensesForm({ expense, onSubmit }: Props) { - const context = trpc.useContext(); + const utils = trpc.useUtils(); const addExpenseMutation = trpc.expenses.addExpense.useMutation({ onSuccess: () => { - context.expenses.getInfinitelyScrollableExpenses.invalidate(); + utils.expenses.getInfinitelyScrollableExpenses.invalidate(); }, }); const editExpense = trpc.expenses.editExpense.useMutation({ onSuccess: () => { - context.expenses.getInfinitelyScrollableExpenses.invalidate(); + utils.expenses.getInfinitelyScrollableExpenses.invalidate(); }, }); @@ -61,6 +61,7 @@ export function ExpensesForm({ expense, onSubmit }: Props) { amount: data.amount, month: getMonthFromIdx(date.getMonth()), year: date.getFullYear(), + day: date.getDate(), description: data.description, processOverXDays: data.processOverXDays, tag: data.tag, @@ -72,6 +73,7 @@ export function ExpensesForm({ expense, onSubmit }: Props) { amount: data.amount, month: getMonthFromIdx(date.getMonth()), year: date.getFullYear(), + day: date.getDate(), description: data.description, processOverXDays: data.processOverXDays, tag: data.tag, diff --git a/src/components/expenses/SetTagForm.tsx b/src/components/expenses/SetTagForm.tsx index 4011185..62e288d 100644 --- a/src/components/expenses/SetTagForm.tsx +++ b/src/components/expenses/SetTagForm.tsx @@ -22,10 +22,10 @@ const SET_EXPENSES_TAG_INPUT = z.object({ }); export function SetExpensesTagForm(props: Props) { - const context = trpc.useContext(); + const utils = trpc.useUtils(); const setExpensesTagMutation = trpc.expenses.setExpensesTag.useMutation({ onSuccess: () => { - context.expenses.getInfinitelyScrollableExpenses.invalidate(); + utils.expenses.getInfinitelyScrollableExpenses.invalidate(); }, }); diff --git a/src/components/hours/HoursForm.tsx b/src/components/hours/HoursForm.tsx index 33a7766..6b69182 100644 --- a/src/components/hours/HoursForm.tsx +++ b/src/components/hours/HoursForm.tsx @@ -23,16 +23,16 @@ interface Props { } export function HoursForm({ hour, onSubmit }: Props) { - const context = trpc.useContext(); + const utils = trpc.useUtils(); const addHourMutation = trpc.hours.addHour.useMutation({ onSuccess: () => { - context.hours.getInfinitelyScrollableHours.invalidate(); + utils.hours.getInfinitelyScrollableHours.invalidate(); }, }); const editHourMutation = trpc.hours.editHour.useMutation({ onSuccess: () => { - context.hours.getInfinitelyScrollableHours.invalidate(); + utils.hours.getInfinitelyScrollableHours.invalidate(); }, }); diff --git a/src/components/income/IncomeForm.tsx b/src/components/income/IncomeForm.tsx index 4281e38..5c1bc3c 100644 --- a/src/components/income/IncomeForm.tsx +++ b/src/components/income/IncomeForm.tsx @@ -24,17 +24,17 @@ interface Props { } export function IncomeForm({ income, onSubmit }: Props) { - const context = trpc.useContext(); + const utils = trpc.useUtils(); const addIncome = trpc.income.addIncome.useMutation({ onSuccess: () => { - context.income.getInfiniteScrollableIncome.invalidate(); + utils.income.getInfiniteScrollableIncome.invalidate(); }, }); const editIncome = trpc.income.editIncome.useMutation({ onSuccess: () => { - context.income.getInfiniteScrollableIncome.invalidate(); + utils.income.getInfiniteScrollableIncome.invalidate(); }, }); @@ -54,6 +54,7 @@ export function IncomeForm({ income, onSubmit }: Props) { amount: data.amount, month: getMonthFromIdx(date.getMonth()), year: date.getFullYear(), + day: date.getDate(), description: data.description, type: data.type, }; diff --git a/src/components/subscriptions/SubscriptionForm.tsx b/src/components/subscriptions/SubscriptionForm.tsx index 7304a19..f34066f 100644 --- a/src/components/subscriptions/SubscriptionForm.tsx +++ b/src/components/subscriptions/SubscriptionForm.tsx @@ -23,17 +23,17 @@ interface Props { } export function SubscriptionForm({ subscription, onSubmit }: Props) { - const context = trpc.useContext(); + const utils = trpc.useUtils(); const addSubscription = trpc.subscriptions.addSubscription.useMutation({ onSuccess: () => { - context.subscriptions.getInfiniteScrollableSubscriptions.invalidate(); + utils.subscriptions.getInfiniteScrollableSubscriptions.invalidate(); }, }); const editSubscription = trpc.subscriptions.editSubscription.useMutation({ onSuccess: () => { - context.subscriptions.getInfiniteScrollableSubscriptions.invalidate(); + utils.subscriptions.getInfiniteScrollableSubscriptions.invalidate(); }, }); diff --git a/src/pages/income.tsx b/src/pages/income.tsx index 04b4d9b..49fde1b 100644 --- a/src/pages/income.tsx +++ b/src/pages/income.tsx @@ -40,11 +40,11 @@ export default function IncomePage() { page, setPage, }); - const context = trpc.useContext(); + const utils = trpc.useUtils(); const deleteIncome = trpc.income.deleteIncome.useMutation({ onSuccess: () => { - context.income.getInfiniteScrollableIncome.invalidate(); + utils.income.getInfiniteScrollableIncome.invalidate(); }, }); diff --git a/src/pages/subscriptions.tsx b/src/pages/subscriptions.tsx index 5c9c4a6..41e2133 100644 --- a/src/pages/subscriptions.tsx +++ b/src/pages/subscriptions.tsx @@ -34,11 +34,11 @@ export default function SubscriptionsPage() { page, setPage, }); - const context = trpc.useContext(); + const utils = trpc.useUtils(); const deleteSubscription = trpc.subscriptions.deleteSubscription.useMutation({ onSuccess: () => { - context.subscriptions.getInfiniteScrollableSubscriptions.invalidate(); + utils.subscriptions.getInfiniteScrollableSubscriptions.invalidate(); }, }); diff --git a/src/server/routers/expenses.ts b/src/server/routers/expenses.ts index 4df8037..da8b70b 100644 --- a/src/server/routers/expenses.ts +++ b/src/server/routers/expenses.ts @@ -15,6 +15,7 @@ export const ADD_EXPENSE_INPUT = z.object({ amount: z.number().min(0.01), year: z.number(), month: z.nativeEnum(Month), + day: z.number(), description: z.string().nullish(), tag: z.nativeEnum(ExpenseTag).nullish(), processOverXDays: z diff --git a/src/server/routers/income.ts b/src/server/routers/income.ts index 38d4729..b8d0599 100644 --- a/src/server/routers/income.ts +++ b/src/server/routers/income.ts @@ -66,6 +66,7 @@ export const incomeRouter = t.router({ type: z.nativeEnum(IncomeType), amount: z.number().min(0.01), year: z.number(), + day: z.number(), description: z.string().nullish(), month: z.nativeEnum(Month), }), @@ -79,7 +80,7 @@ export const incomeRouter = t.router({ amount: input.amount, description: input.description, date: { - create: { month: input.month, year: input.year }, + create: { month: input.month, year: input.year, day: input.day }, }, user: { connect: { id: userId } }, }, @@ -97,6 +98,7 @@ export const incomeRouter = t.router({ year: z.number(), description: z.string().nullish(), month: z.nativeEnum(Month), + day: z.number(), }), ) .mutation(async ({ ctx, input }) => { @@ -112,7 +114,7 @@ export const incomeRouter = t.router({ type: input.type, amount: input.amount, description: input.description, - date: { update: { month: input.month, year: input.year } }, + date: { update: { month: input.month, year: input.year, day: input.day } }, }, select: incomeSelect, });