diff --git a/lib/api/quizRelase.ts b/lib/api/quizRelase.ts index 8761234..d5c1644 100644 --- a/lib/api/quizRelase.ts +++ b/lib/api/quizRelase.ts @@ -38,7 +38,13 @@ const DeviceType = device.type; let Device = md.mobile(); if (Device === null) { Device = userAgent; } -export const publicationMakeRequest = ({ url, body }: any) => { +type PublicationMakeRequestParams = { + url: string; + body: FormData; + method: "POST"; +} + +export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestParams) => { return axios(url, { data: body, headers: { @@ -56,7 +62,7 @@ export const publicationMakeRequest = ({ url, body }: any) => { export async function getData(quizId: string): Promise<{ data: GetQuizDataResponse | null; isRecentlyCompleted: boolean; - error?: any; + error?: AxiosError; }> { try { const { data, headers } = await axios( @@ -116,7 +122,14 @@ export async function getQuizData(quizId: string) { return res; } -export function sendAnswer({ questionId, body, qid, preview }: any) { +type SendAnswerProps = { + questionId: string; + body: string | string[]; + qid: string; + preview: boolean; +} + +export function sendAnswer({ questionId, body, qid, preview }: SendAnswerProps) { if (preview) return; const formData = new FormData(); @@ -138,11 +151,26 @@ export function sendAnswer({ questionId, body, qid, preview }: any) { } //body ={file, filename} -export function sendFile({ questionId, body, qid, preview }: any) { - if (preview) return; +type SendFileParams = { + questionId: string; + body: { + name: string; + file: File; + preview: boolean; + }; + qid: string; +} + +type Answer = { + question_id: string; + content: string; +}; + +export function sendFile({ questionId, body, qid }: SendFileParams) { + if (body.preview) return; const formData = new FormData(); - const answers: any = [ + const answers: Answer[] = [ { question_id: questionId, content: "file:" + body.name, @@ -162,7 +190,20 @@ export function sendFile({ questionId, body, qid, preview }: any) { } //форма контактов -export function sendFC({ questionId, body, qid, preview }: any) { +export type SendFCParams = { + questionId: string; + body: { + name?: string; + email?: string; + phone?: string; + address?: string; + customs?: Record; + }; + qid: string; + preview: boolean; +} + +export function sendFC({ questionId, body, qid, preview }: SendFCParams) { if (preview) return; const formData = new FormData(); diff --git a/lib/assets/icons/Info.tsx b/lib/assets/icons/Info.tsx index b56f67f..f319760 100644 --- a/lib/assets/icons/Info.tsx +++ b/lib/assets/icons/Info.tsx @@ -4,7 +4,7 @@ type InfoProps = { width?: number; height?: number; sx?: SxProps; - onClick?: any; + onClick?: () => void; className?: string; color?: string }; diff --git a/lib/components/ViewPublicationPage/ContactForm.tsx b/lib/components/ViewPublicationPage/ContactForm.tsx index 657ea51..b486637 100644 --- a/lib/components/ViewPublicationPage/ContactForm.tsx +++ b/lib/components/ViewPublicationPage/ContactForm.tsx @@ -1,4 +1,4 @@ -import { FC, useRef, useState, useEffect } from "react"; +import {FC, useRef, useState, useEffect, Dispatch, SetStateAction} from "react"; import AddressIcon from "@icons/ContactFormIcon/AddressIcon"; import EmailIcon from "@icons/ContactFormIcon/EmailIcon"; import NameIcon from "@icons/ContactFormIcon/NameIcon"; @@ -18,7 +18,7 @@ import { import CustomCheckbox from "@ui_kit/CustomCheckbox"; import { DESIGN_LIST } from "@/utils/designList"; -import { sendFC } from "@api/quizRelase"; +import {sendFC, SendFCParams} from "@api/quizRelase"; import { useQuizData } from "@contexts/QuizDataContext"; import { NameplateLogo } from "@icons/NameplateLogo"; import { QuizQuestionResult } from "@model/questionTypes/result"; @@ -26,6 +26,31 @@ import { AnyTypedQuizQuestion } from "@model/questionTypes/shared"; import { quizThemes } from "@utils/themes/Publication/themePublication"; import { enqueueSnackbar } from "notistack"; import { useRootContainerSize } from "../../contexts/RootContainerWidthContext"; +import { + FormContactFieldData, + FormContactFieldName, +} from "@model/settingsData.ts"; + +type InputProps = { + title: string; + desc: string; + Icon: FC<{ color: string; backgroundColor: string; }>; + onChange: TextFieldProps["onChange"]; + id: string; +}; + +type InputsProps = { + name: string; + setName: Dispatch>; + email: string; + setEmail: Dispatch>; + phone: string; + setPhone: Dispatch>; + text: string; + setText: Dispatch>; + adress: string; + setAdress: Dispatch>; +}; const TextField = MuiTextField as unknown as FC; // temporary fix ts(2590) const EMAIL_REGEXP = @@ -86,7 +111,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => { const inputHC = async () => { const FC = settings.cfg.formContact.fields || settings.cfg.formContact; - const body = {} as any; + const body:SendFCParams["body"] = {} if (name.length > 0) body.name = name; if (email.length > 0) body.email = email; if (phone.length > 0) body.phone = phone; @@ -113,19 +138,19 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => { } }; - const FCcopy: any = + const FCcopy: Record = settings.cfg.formContact.fields || settings.cfg.formContact; - const filteredFC: any = {}; + const filteredFC: Partial> = {}; for (const i in FCcopy) { - const field = FCcopy[i]; + const field = FCcopy[i as keyof typeof FCcopy]; if (field.used) { - filteredFC[i] = field; + filteredFC[i as FormContactFieldName] = field; } } async function handleShowResultsClick() { - const FC: any = settings.cfg.formContact.fields; + const FC = settings.cfg.formContact.fields; if (FC["email"].used !== EMAIL_REGEXP.test(email)) { return enqueueSnackbar("введена некорректная почта"); } @@ -145,7 +170,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => { try { await inputHC(); fireOnce.current = false; - const sessions: any = JSON.parse( + const sessions = JSON.parse( localStorage.getItem("sessions") || "{}" ); sessions[quizId] = Date.now(); @@ -389,7 +414,7 @@ const Inputs = ({ setText, adress, setAdress, -}: any) => { +}: InputsProps) => { const { settings } = useQuizData(); const FC = settings.cfg.formContact.fields; @@ -463,27 +488,15 @@ const Inputs = ({ } }; -const CustomInput = ({ - title, - desc, - Icon, - onChange, - id, -}: { - id: string; - title: string; - desc: string; - Icon: FC<{ color: string; backgroundColor: string }>; - onChange: TextFieldProps["onChange"]; -}) => { - const theme = useTheme(); - const isMobile = useRootContainerSize() < 600; - const { settings } = useQuizData(); - return ( - - - {title} - +const CustomInput = ({ title, desc, Icon, onChange, id }: InputProps) => { + const theme = useTheme(); + const isMobile = useRootContainerSize() < 600; + const { settings } = useQuizData(); + return ( + + + {title} + { interface Props { currentQuestion: QuizQuestionText; - answer: any; + answer?: Answer; inputHC: (a: string) => void; stepNumber?: number | null; } diff --git a/lib/model/settingsData.ts b/lib/model/settingsData.ts index 0bb178c..cc5e851 100644 --- a/lib/model/settingsData.ts +++ b/lib/model/settingsData.ts @@ -118,7 +118,7 @@ export type FormContactFieldName = | "text" | "address"; -type FormContactFieldData = { +export type FormContactFieldData = { text: string; innerText: string; key: string; diff --git a/lib/stores/quizView.ts b/lib/stores/quizView.ts index abf9181..07f87db 100644 --- a/lib/stores/quizView.ts +++ b/lib/stores/quizView.ts @@ -6,9 +6,11 @@ import { createContext, useContext } from "react"; import { createStore, useStore } from "zustand"; import { immer } from "zustand/middleware/immer"; +export type Answer = string | string[] | Moment; + type QuestionAnswer = { questionId: string; - answer: string | string[] | Moment; + answer: Answer }; type OwnVariant = { @@ -99,4 +101,4 @@ export const createQuizViewStore = () => createStore; // temporary fix ts(2590) interface CustomTextFieldProps { placeholder: string; - value?: string; + value?: Answer; error?: string; onChange?: (event: ChangeEvent) => void; onKeyDown?: (event: KeyboardEvent) => void;