Skip to content

Commit

Permalink
fix: don't unpack date
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 13, 2024
1 parent c35869e commit b32fd6b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
13 changes: 0 additions & 13 deletions src/utils/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,3 @@ export function handleResultState<QueryArg, ResultType>(
// Have yet to call the API.
return loadingNode
}

export function prepareArg(arg: unknown): void {
if (typeof arg === "object" && arg !== null) {
const _arg = arg as Record<string, unknown>
for (const property in _arg) {
let value = _arg[property]
if (value instanceof Date) value = value.toISOString()
else if (typeof value === "object" && value !== null) prepareArg(value)

_arg[property] = value
}
}
}
3 changes: 0 additions & 3 deletions src/utils/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { FieldValidator, FormikHelpers } from "formik"
import { ValidationError, type Schema, type ValidateOptions } from "yup"

import { excludeKeyPaths } from "./general"
import { prepareArg } from "./api"

export function isFormError(error: unknown): boolean {
return (
Expand Down Expand Up @@ -82,8 +81,6 @@ export function submitForm<

if (exclude) arg = excludeKeyPaths(arg, exclude)

prepareArg(arg)

trigger(arg)
.unwrap()
.then(result => {
Expand Down
9 changes: 7 additions & 2 deletions src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,15 @@ export function excludeKeyPaths(
function _excludeKeyPaths(obj: object, path: string[]) {
return Object.fromEntries(
Object.entries(obj)
.map(([key, value]) => {
.map(([key, value]: [string, unknown]) => {
const _path = [...path, key]

if (typeof value === "object") value = _excludeKeyPaths(value, _path)
if (
typeof value === "object" &&
value !== null &&
!(value instanceof Date)
)
value = _excludeKeyPaths(value, _path)

return exclude.includes(_path.join(delimiter)) ? [] : [key, value]
})
Expand Down

0 comments on commit b32fd6b

Please sign in to comment.