Skip to content

Commit

Permalink
Fix File Formatting - pass Prettier check
Browse files Browse the repository at this point in the history
  • Loading branch information
parthokunda committed Aug 2, 2024
1 parent 0b851ad commit c01dd67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
17 changes: 8 additions & 9 deletions src/components/expense-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
import { cn } from '@/lib/utils'
import { zodResolver } from '@hookform/resolvers/zod'
import { Save } from 'lucide-react'
import Mexp from 'math-expression-evaluator'
import Link from 'next/link'
import { useSearchParams } from 'next/navigation'
import { useState } from 'react'
Expand All @@ -52,7 +53,6 @@ import { match } from 'ts-pattern'
import { DeletePopup } from './delete-popup'
import { extractCategoryFromTitle } from './expense-form-actions'
import { Textarea } from './ui/textarea'
import Mexp from 'math-expression-evaluator'

const mexp = new Mexp()

Expand Down Expand Up @@ -331,7 +331,7 @@ export function ExpenseForm({
inputMode="decimal"
placeholder="0.00"
onChange={(event) => {
let v = (event.target.value)
let v = event.target.value
if (v === '') {
setEvaluatedAmount('0')
} else {
Expand Down Expand Up @@ -360,11 +360,11 @@ export function ExpenseForm({
</FormControl>
</div>
<FormMessage />
<div className="flex flex-row gap-2 items-center justify-between">
<div className="text-white/50 pl-5">
{' = ' + evaluatedAmount}
</div>
{!isIncome && (
<div className="flex flex-row gap-2 items-center justify-between">
<div className="text-white/50 pl-5">
{' = ' + evaluatedAmount}
</div>
{!isIncome && (
<FormField
control={form.control}
name="isReimbursement"
Expand All @@ -376,9 +376,8 @@ export function ExpenseForm({
onCheckedChange={field.onChange}
/>
</FormControl>
<FormLabel>Reimbursement</FormLabel>
<FormLabel>Reimbursement</FormLabel>
</FormItem>

)}
/>
)}
Expand Down
17 changes: 8 additions & 9 deletions src/lib/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SplitMode } from '@prisma/client'
import * as z from 'zod'
import Mexp from 'math-expression-evaluator'
import * as z from 'zod'

const mexp = new Mexp()

Expand Down Expand Up @@ -54,15 +54,14 @@ export const expenseFormSchema = z
[
z.number(),
z.string().transform((value, ctx) => {
let valueAsNumber = NaN;
let valueAsNumber = NaN
try {
valueAsNumber =
Number(
mexp
.eval(value)
.toFixed(2)
.replace(/\.?0+$/, '') // replace trailing zeros
)
valueAsNumber = Number(
mexp
.eval(value)
.toFixed(2)
.replace(/\.?0+$/, ''), // replace trailing zeros
)
} finally {
if (Number.isNaN(valueAsNumber))
ctx.addIssue({
Expand Down

0 comments on commit c01dd67

Please sign in to comment.