Skip to content

Commit

Permalink
chore: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Feb 11, 2024
1 parent 4bfe293 commit 19adcea
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/components/expenses/ExpensesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
});

Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/components/expenses/SetTagForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
});

Expand Down
6 changes: 3 additions & 3 deletions src/components/hours/HoursForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
});

Expand Down
7 changes: 4 additions & 3 deletions src/components/income/IncomeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
});

Expand All @@ -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,
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/subscriptions/SubscriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/pages/income.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/pages/subscriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
});

Expand Down
1 change: 1 addition & 0 deletions src/server/routers/expenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/server/routers/income.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
Expand All @@ -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 } },
},
Expand All @@ -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 }) => {
Expand All @@ -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,
});
Expand Down

0 comments on commit 19adcea

Please sign in to comment.