diff --git a/app/utils/yup-action.ts b/app/utils/yup-action.ts index 7b55d04..6a9e680 100644 --- a/app/utils/yup-action.ts +++ b/app/utils/yup-action.ts @@ -1,18 +1,33 @@ import * as yup from 'yup' +export async function yupAction( + request: FormData, + schema: T, +): Promise> + export async function yupAction( request: Request, schema: T, - type: 'form-data' | 'search-params', -): Promise> { + type?: 'form-data' | 'search-params', +): Promise> + +export async function yupAction( + request: Request | FormData, + schema: T, + type?: 'form-data' | 'search-params', +) { let data: any = null - if (type === 'form-data') { + if (request instanceof FormData) { + data = Object.fromEntries(request) + } + + if (type === 'form-data' && request instanceof Request) { const formData = await request.formData() data = Object.fromEntries(formData) } - if (type === 'search-params') { + if (type === 'search-params' && request instanceof Request) { const { searchParams } = new URL(request.url) data = Object.fromEntries(searchParams) }