Skip to content

Commit

Permalink
pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
cohenaj194 committed Nov 30, 2024
1 parent a6c2176 commit c86ddcf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 30 deletions.
39 changes: 21 additions & 18 deletions app/components/form/WoW/OutOfStockForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,32 @@ const OutOfStockForm = ({
const parseCategories = (value: string | number | number[]): number[] => {
if (Array.isArray(value)) return value
if (typeof value === 'string' && value.trim() !== '') {
return value.split(',').map(Number).filter(n => !isNaN(n))
return value
.split(',')
.map(Number)
.filter((n) => !isNaN(n))
}
return []
}

return (
<div className="pt-3 flex flex-col">
<ExpansionSelect
defaultValue={defaultValues.expansionNumber}
onChange={(value) => onFormChange('expansionNumber', value)}

Check failure on line 29 in app/components/form/WoW/OutOfStockForm/index.tsx

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/components/form/WoW/OutOfStockForm/index.tsx#L29

Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function.
/>
<Filter
formName="includeCategories"
defaultValue={parseCategories(defaultValues.includeCategories)}
options={wowCategories}
title={'Item Categories (Include)'}
/>
<Filter
formName="excludeCategories"
defaultValue={parseCategories(defaultValues.excludeCategories)}
options={wowCategories}
title={'Item Categories (Exclude)'}
/>
<InputWithLabel
defaultValue={defaultValues.salesPerDay}
type="number"
Expand Down Expand Up @@ -82,24 +101,8 @@ const OutOfStockForm = ({
step={1}
onChange={(e) => onFormChange('rankingWP', e.target.value)}
/>
<ExpansionSelect
defaultValue={defaultValues.expansionNumber}
onChange={(value) => onFormChange('expansionNumber', value)}
/>
<Filter
formName="includeCategories"
defaultValue={parseCategories(defaultValues.includeCategories)}
options={wowCategories}
title={'Item Categories (Include)'}
/>
<Filter
formName="excludeCategories"
defaultValue={parseCategories(defaultValues.excludeCategories)}
options={wowCategories}
title={'Item Categories (Exclude)'}
/>
</div>
)
}

export default OutOfStockForm
export default OutOfStockForm
42 changes: 30 additions & 12 deletions app/routes/wow.out-of-stock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ const validateInput = z.object({
populationBlizz: z.string().transform((value) => parseInt(value)),

Check failure on line 56 in app/routes/wow.out-of-stock.tsx

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/routes/wow.out-of-stock.tsx#L56

Unsafe argument of type `any` assigned to a parameter of type `string`.

Check failure on line 56 in app/routes/wow.out-of-stock.tsx

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/routes/wow.out-of-stock.tsx#L56

Unsafe assignment of an error typed value.

Check failure on line 56 in app/routes/wow.out-of-stock.tsx

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/routes/wow.out-of-stock.tsx#L56

Unsafe member access .string on an `error` typed value.
rankingWP: z.string().transform((value) => parseInt(value)),
expansionNumber: z.string().transform((value) => parseInt(value)),
includeCategories: z.string().transform((value) =>
value.trim() === '' ? [] : value.split(',').map((value) => parseInt(value))
),
excludeCategories: z.string().transform((value) =>
value.trim() === '' ? [] : value.split(',').map((value) => parseInt(value))
)
includeCategories: z
.string()
.transform((value) =>
value.trim() === ''
? []
: value.split(',').map((value) => parseInt(value))
),
excludeCategories: z
.string()
.transform((value) =>
value.trim() === ''
? []
: value.split(',').map((value) => parseInt(value))
)
})

export const loader: LoaderFunction = async ({ request }) => {
Expand Down Expand Up @@ -106,7 +114,10 @@ export const action: ActionFunction = async ({ request }) => {

if (!validatedFormData.success) {
return json({
exception: parseZodErrorsToDisplayString(validatedFormData.error, inputMap)
exception: parseZodErrorsToDisplayString(
validatedFormData.error,

Check failure on line 118 in app/routes/wow.out-of-stock.tsx

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/routes/wow.out-of-stock.tsx#L118

Unsafe member access .error on an `error` typed value.
inputMap
)
})
}

Expand All @@ -131,14 +142,18 @@ export const action: ActionFunction = async ({ request }) => {
})
} catch (error) {
return json({
exception: error instanceof Error ? error.message : 'An unexpected error occurred'
exception:
error instanceof Error ? error.message : 'An unexpected error occurred'
})
}
}

const OutOfStock = () => {
const loaderData = useLoaderData<typeof loader>()
const result = useActionData<{ data?: OutOfStockItem[], exception?: string }>()
const result = useActionData<{
data?: OutOfStockItem[]
exception?: string
}>()
const transition = useNavigation()
const isSubmitting = transition.state === 'submitting'
const [searchParams, setSearchParams] = useState(loaderData)
Expand All @@ -158,7 +173,10 @@ const OutOfStock = () => {
}
}

const handleFormChange = (name: keyof typeof defaultFormValues, value: string) => {
const handleFormChange = (
name: keyof typeof defaultFormValues,
value: string
) => {
handleSearchParamChange(name, value)
setSearchParams((prev) => ({ ...prev, [name]: value }))
}
Expand All @@ -183,8 +201,8 @@ const OutOfStock = () => {
/>
</div>
</div>
<OutOfStockForm
defaultValues={searchParams}
<OutOfStockForm
defaultValues={searchParams}
onFormChange={handleFormChange}
/>
</SmallFormContainer>
Expand Down

0 comments on commit c86ddcf

Please sign in to comment.