Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { UploadBy } from "./FormWithFileInput";
export const FormWithFileInputButton: React.FC = () => {
const { t } = useTranslation("files");

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const onSubmit = (values: any) => {
const onSubmit = (values: Record<string, string | Blob>) => {
const formData = new FormData();

for (const name in values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import React from "react";
export const FormWithFileInput: React.FC = () => {
const { t } = useTranslation("files");

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const onSubmit = (values: any) => {
const onSubmit = (values: Record<string, string | Blob>) => {
const formData = new FormData();

for (const name in values) {
Expand Down
3 changes: 1 addition & 2 deletions apps/demo/src/Views/Form/components/FormInput/FormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ export const FormInputDemo = () => {
}),
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleSubmit = (_formData: any) => {
const handleSubmit = (_formData: Record<string, unknown>) => {
setFormData(JSON.stringify(_formData, null, 4));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ type Properties = {
export const FormInputFields = ({ checkFilledState }: Properties) => {
const [t] = useTranslation("form");
const [isLoading, setIsLoading] = useState(false);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [options, setOptions] = useState<any>([]);
const [options, setOptions] = useState<
{ title: string; [key: string]: unknown }[]
>([]);
const {
register,
getFieldState,
Expand All @@ -36,15 +37,13 @@ export const FormInputFields = ({ checkFilledState }: Properties) => {

const [filled, valid, invalid] = watch(["filled", "valid", "invalid"]);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleDataFetch = (value: any) => {
const handleDataFetch = (value: string | number | readonly string[]) => {
setIsLoading(true);
fetch(`https://api.escuelajs.co/api/v1/products/?title=${value}`)
.then(async (response) => {
const data = await response.json();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
setOptions(data.map((item: any) => item));
setOptions(data.map((item: unknown) => item));
setIsLoading(false);
})
.catch((err) => console.log("err", err)); // eslint-disable-line no-console
Expand Down
9 changes: 6 additions & 3 deletions apps/demo/src/Views/Ui/components/DropdownMenuDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ export const DropdownMenuDemo = () => {
},
];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const template = (item: any) => {
const template = (item: MenuItem) => {
return (
<>
<i className={item.icon} style={{ marginRight: "0.5rem" }}></i>
{typeof item.icon === "string" ? (
<i className={item.icon} style={{ marginRight: "0.5rem" }}></i>
) : (
item.icon
)}
<span>{item.label}</span>
</>
);
Expand Down
31 changes: 15 additions & 16 deletions apps/demo/src/Views/Ui/components/FormWidgets/Typeahead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,51 +52,50 @@ export const TypeaheadDemo = () => {
const navigate = useNavigate();

const [isLoading, setIsLoading] = useState(false);
const [options, setOptions] = useState([]);
const [suggestions, setSuggestions] = useState([]);
const [options, setOptions] = useState<string[]>([]);
const [suggestions, setSuggestions] = useState<string[]>([]);
const [customSuggestions, setCustomSuggestions] = useState<
Array<CustomSuggestionType>
>([]);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleDataFetch = (value: any) => {
const handleDataFetch = (value: string | number | readonly string[]) => {
setIsLoading(true);
fetch(`https://api.escuelajs.co/api/v1/products/?title=${value}`)
.then(async (response) => {
const data = await response.json();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setOptions(data.map((item: any) => item.title));

setOptions(data.map((item: { title: string }) => item.title));
setIsLoading(false);
})
.catch((err) => console.log("err", err)); // eslint-disable-line no-console
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleServerChange = (value: any) => {
const handleServerChange = (value?: string) => {
console.log("selected server value:", value); // eslint-disable-line no-console
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleDataFilter = (value: any) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let newSuggestions: any = [];
const handleDataFilter = (value: string | number | readonly string[]) => {
let newSuggestions = [];

if (value.length > 0) {
if (typeof value === "string" && value.length) {
newSuggestions = items.filter((_value) =>
_value.toLowerCase().startsWith(value.toLowerCase()),
);

setSuggestions(newSuggestions);
}
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleCustomSuggestionDataFilter = (value: any) => {
const handleCustomSuggestionDataFilter = (
value: string | number | readonly string[],
) => {
let newSuggestions = [];

if (value && value.length) {
if (typeof value === "string" && value.length) {
newSuggestions = suggestionItems.filter((_value) =>
_value.value.toLowerCase().includes(value.toLowerCase()),
);

setCustomSuggestions(newSuggestions);
}
};
Expand Down
13 changes: 9 additions & 4 deletions apps/demo/src/Views/Ui/components/Stepper/Stepper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { useTranslation } from "@prefabs.tech/react-i18n";
import { Button, Divider, Stepper, Page } from "@prefabs.tech/react-ui";
import {
Button,
Divider,
Stepper,
Page,
IStepEvent,
} from "@prefabs.tech/react-ui";
import { useState } from "react";
import { useNavigate } from "react-router-dom";

Expand Down Expand Up @@ -127,9 +133,8 @@ export const StepperDemo = () => {
hideButtons={true}
activeIndex={activeIndex}
readOnly={true}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onChange={(event: any) => {
setActiveIndex(event.index);
onChange={(event: IStepEvent) => {
event.index && setActiveIndex(event.index);
}}
align="start"
/>
Expand Down
10 changes: 4 additions & 6 deletions apps/demo/src/Views/Ui/components/TabView/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
export const addTab = (
key: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
visibleTabs: any[],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setVisibleTabs: any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setActive: any,
visibleTabs: string[],
setVisibleTabs: (value: string[]) => void,
setActive: (value: string) => void,
) => {
const existingTab = visibleTabs.find((tab) => tab === key);

if (existingTab) {
setActive(existingTab);
} else {
Expand Down
9 changes: 3 additions & 6 deletions apps/demo/src/Views/Ui/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export const TableDemo = () => {
},
];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const inDateRangeFilter: FilterFunction<any> = (
const inDateRangeFilter: FilterFunction<TData> = (
row,
columnId,
value: [Date, Date],
Expand All @@ -104,8 +103,7 @@ export const TableDemo = () => {
);
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const customEqualStringFilter: FilterFunction<any> = (
const customEqualStringFilter: FilterFunction<TData> = (
row,
columnId,
value: string,
Expand Down Expand Up @@ -1267,8 +1265,7 @@ export const TableDemo = () => {
return true;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const updatedFilterValue = filterValue.map((value: any) => {
const updatedFilterValue = filterValue.map((value: unknown) => {
switch (value) {
case "true":
return true;
Expand Down
6 changes: 2 additions & 4 deletions packages/form/src/components/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ interface IDateInput {
showInvalidState?: boolean;
showValidState?: boolean;
submitCount?: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getFieldState?: UseFormGetFieldState<any>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
register?: UseFormRegister<any>;
getFieldState?: UseFormGetFieldState<Record<string, unknown>>;
register?: UseFormRegister<Record<string, unknown>>;
}

// TODO use Input component from @prefabs.tech/react-ui
Expand Down
4 changes: 2 additions & 2 deletions packages/form/src/components/Email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ interface IProperties extends IInputProperties {
showInvalidState?: boolean;
submitCount?: number;
/** @deprecated */
getFieldState?: UseFormGetFieldState<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
getFieldState?: UseFormGetFieldState<Record<string, unknown>>;
/** @deprecated */
register?: UseFormRegister<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
register?: UseFormRegister<Record<string, unknown>>;
}

export const Email: React.FC<IProperties> = ({
Expand Down
11 changes: 4 additions & 7 deletions packages/form/src/components/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { zodResolver } from "@hookform/resolvers/zod";
import React, { Children, createElement } from "react";
import { UseFormProps, useForm } from "react-hook-form";
import { ZodEffects, ZodObject } from "zod";
import { AnyZodObject } from "zod";

interface IForm extends UseFormProps {
className?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
children: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
validationSchema?: ZodObject<any> | ZodEffects<any>;
children: JSX.Element;
validationSchema?: AnyZodObject;
html5Validation?: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onSubmit: (data: any) => void;
onSubmit: (data: Record<string, unknown>) => void;
}

export const Form: React.FC<IForm> = ({
Expand Down
10 changes: 4 additions & 6 deletions packages/form/src/components/FormProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { zodResolver } from "@hookform/resolvers/zod";
import React, { useEffect } from "react";
import { UseFormProps, useForm, FormProvider } from "react-hook-form";
import { ZodEffects, ZodObject } from "zod";
import { AnyZodObject } from "zod";

import { FormSubmitOptions } from "..";

interface IForm extends UseFormProps {
className?: string;
children: React.ReactNode;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
validationSchema?: ZodObject<any> | ZodEffects<any>;
validationSchema?: AnyZodObject;
html5Validation?: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onSubmit: (data: any, options?: FormSubmitOptions) => any;
onSubmit: (data: any, options?: FormSubmitOptions) => unknown;
validationTriggerKey?: string;
}

Expand All @@ -30,8 +29,7 @@ export const Provider: React.FC<IForm> = ({
...useFormOptions,
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleOnSubmit = async (data: any) => {
const handleOnSubmit = async (data: Record<string, unknown>) => {
try {
const formSubmitOptions = {
clearErrors: methods.clearErrors,
Expand Down
4 changes: 2 additions & 2 deletions packages/form/src/components/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ interface ITextInput extends IInputProperties {
showInvalidState?: boolean;
submitCount?: number;
/** @deprecated */
getFieldState?: UseFormGetFieldState<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
getFieldState?: UseFormGetFieldState<Record<string, unknown>>;
/** @deprecated */
register?: UseFormRegister<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
register?: UseFormRegister<Record<string, unknown>>;
}

export const TextInput: React.FC<ITextInput> = ({
Expand Down
6 changes: 2 additions & 4 deletions packages/form/src/components/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ interface ITextarea extends ITextareaProperties {
showInvalidState?: boolean;
submitCount?: number;
/** @deprecated */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getFieldState?: UseFormGetFieldState<any>;
getFieldState?: UseFormGetFieldState<Record<string, unknown>>;
/** @deprecated */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
register?: UseFormRegister<any>;
register?: UseFormRegister<Record<string, unknown>>;
}

export const Textarea: React.FC<ITextarea> = ({
Expand Down
12 changes: 4 additions & 8 deletions packages/form/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ interface PasswordErrorMessages {

interface CustomInputProperties {
disabled?: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getFieldState?: UseFormGetFieldState<any>;
getFieldState?: UseFormGetFieldState<Record<string, unknown>>;
helperText?: string;
label?: string | React.ReactNode;
name: string;
placeholder?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
register?: UseFormRegister<any>;
register?: UseFormRegister<Record<string, unknown>>;
showValidState?: boolean;
showInvalidState?: boolean;
submitCount?: number;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type AdditionalFormSchema = Zod.ZodObject<any>;
export type AdditionalFormSchema = Zod.ZodObject<Zod.ZodRawShape>;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type AdditionalDefaultValues = Record<string, any>;
export type AdditionalDefaultValues = Record<string, unknown>;

export type RenderAdditionalFormFields = (
formContext: typeof useFormContext,
Expand Down
5 changes: 2 additions & 3 deletions packages/layout/setup-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { vi } from "vitest";

// from i18n documentation https://react.i18next.com/misc/testing
vi.mock("@prefabs.tech/react-i18n", async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const actual: any = await vi.importActual("@prefabs.tech/react-i18n");
const actual = await vi.importActual("@prefabs.tech/react-i18n");

return {
...actual,
useTranslation: () => {
return {
t: (string_) => string_,
t: (string_: string) => string_,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
Expand Down
Loading
Loading