fix
This commit is contained in:
parent
c858803cb0
commit
af89180d07
|
|
@ -12,7 +12,11 @@ const SelectTag: React.FC = () => {
|
|||
const [NewAdditionalData, setNewAdditionalData] = useState({})
|
||||
const formik = useFormikContext<any>();
|
||||
const handleChange = (value: any,option:any) => {
|
||||
console.log(option);
|
||||
console.log(value);
|
||||
const newSelectedOption = option?.pop()
|
||||
console.log(newSelectedOption);
|
||||
|
||||
const newObject = {
|
||||
id:newSelectedOption?.id,
|
||||
name:newSelectedOption?.name
|
||||
|
|
@ -24,6 +28,7 @@ const SelectTag: React.FC = () => {
|
|||
};
|
||||
|
||||
const handleSearch = useDebounce((value: string) => {
|
||||
console.log(value,"value");
|
||||
|
||||
setSearchValue(value);
|
||||
});
|
||||
|
|
@ -43,19 +48,23 @@ const SelectTag: React.FC = () => {
|
|||
});
|
||||
|
||||
const [t] = useTranslation();
|
||||
const initialData = formik?.values?.tags?.filter((item:any)=>{
|
||||
return item?.id
|
||||
|
||||
}) ?? []
|
||||
|
||||
|
||||
|
||||
const options = data?.data ?? [];
|
||||
const additionalData =
|
||||
options.length < 1 && searchValue.length > 1 && !isLoading
|
||||
? [{ id: searchValue, name: searchValue }]
|
||||
: [];
|
||||
console.log(formik?.values?.tags,"formik?.values?.tags");
|
||||
|
||||
const value =
|
||||
formik?.values?.tags?.map((item: any) => item?.id ?? item) ?? [];
|
||||
|
||||
const AllOptions = [...options, ...additionalData,NewAdditionalData,...(formik?.values?.tags ?? {})];
|
||||
console.log(AllOptions,"AllOptions");
|
||||
const AllOptions = [...options, ...additionalData,NewAdditionalData, ...(initialData)];
|
||||
|
||||
const uniqueOptions = Array.from(
|
||||
new Map(
|
||||
|
|
@ -65,7 +74,6 @@ const SelectTag: React.FC = () => {
|
|||
).values()
|
||||
);
|
||||
|
||||
console.log(uniqueOptions,"uniqueOptions");
|
||||
|
||||
return (
|
||||
<div className="SelectTag">
|
||||
|
|
|
|||
|
|
@ -3,36 +3,34 @@ import React from "react";
|
|||
import { useTranslation } from "react-i18next";
|
||||
import { GoArrowSwitch } from "react-icons/go";
|
||||
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
|
||||
import { QUESTION_OBJECT_KEY } from "../../config/AppKey";
|
||||
import { Popconfirm, Popover } from "antd";
|
||||
import { CombinationKeyEnum } from "../../enums/CombinationKeyEnum";
|
||||
import { PopconfirmProps } from "antd/lib";
|
||||
|
||||
const Header = () => {
|
||||
const [t] = useTranslation();
|
||||
const { values, setFieldValue, setValues } = useFormikContext<any>();
|
||||
const { values, setValues } = useFormikContext<any>();
|
||||
const { isBseQuestion, setIsBseQuestion } = useObjectToEdit();
|
||||
const { setSavedQuestionData } = useObjectToEdit();
|
||||
console.log(values,"values");
|
||||
|
||||
|
||||
const isEdited = ()=>{
|
||||
|
||||
if(isBseQuestion || values?.isBase === 1){
|
||||
|
||||
const content = !values?.content ;
|
||||
const content_image = !values?.content_image ;
|
||||
const hint = !values?.hint ;
|
||||
const Questions = values?.Questions?.length <= 1 && values?.Questions?.[0]?.answers?.length === 0 ;
|
||||
|
||||
if(content && content_image && hint && Questions) {
|
||||
const Questions = values?.Questions?.length <= 1 && values?.Questions?.[0]?.answers?.length === 0 ;
|
||||
const defaultQuestionHint = Object.keys(values?.Questions?.[0] ?? {})?.length <= 1
|
||||
|
||||
|
||||
|
||||
if(content && content_image && Questions && defaultQuestionHint) {
|
||||
return false
|
||||
}
|
||||
}else{
|
||||
const content = !values?.content ;
|
||||
const content_image = !values?.content_image ;
|
||||
const hint = !values?.hint ;
|
||||
const answers = !values?.answers ;
|
||||
const answers = !(values?.answers?.length > 0) ;
|
||||
const tags = !(values?.tags?.length > 0) ;
|
||||
if(content && content_image && hint && answers && tags) {
|
||||
return false
|
||||
|
|
@ -40,26 +38,20 @@ const Header = () => {
|
|||
}
|
||||
return true
|
||||
}
|
||||
console.log(isEdited(),"isEdited");
|
||||
|
||||
const handleChange = () => {
|
||||
setSavedQuestionData(null);
|
||||
localStorage.removeItem(QUESTION_OBJECT_KEY);
|
||||
if (isBseQuestion) {
|
||||
setIsBseQuestion(false);
|
||||
setValues(null);
|
||||
setFieldValue("isBase", 0);
|
||||
} else {
|
||||
setIsBseQuestion(true);
|
||||
setValues(null);
|
||||
setFieldValue("isBase", 1);
|
||||
}
|
||||
};
|
||||
|
||||
const confirm: PopconfirmProps['onConfirm'] = (e) => {
|
||||
console.log(e);
|
||||
setTimeout(() => {
|
||||
handleChange()
|
||||
handleChange() ;
|
||||
}, 500);
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import React, { lazy, Suspense } from "react";
|
||||
import React, { lazy, Suspense, useEffect } from "react";
|
||||
import { useAddKeyToData, Table, useTranslation, usePagination } from ".";
|
||||
import { DataTableProps } from "../../../types/Table";
|
||||
import { useDataTableState } from "../../../zustand/TabState";
|
||||
const NotFoundLottie = React.lazy(
|
||||
() => import("../../../Components/Lottie/NotFound/NotFoundLottie"),
|
||||
);
|
||||
|
|
@ -17,11 +18,16 @@ const DataTable: React.FC<DataTableProps> = ({
|
|||
const columns = useColumns();
|
||||
const { pagination, handlePageChange } = usePagination(response?.data);
|
||||
const [t] = useTranslation();
|
||||
const getRowClassName = (record: any, index: number): string => {
|
||||
const getRowClassName = (_record: any, index: number): string => {
|
||||
return index % 2 === 0 ? "even-row" : "odd-row";
|
||||
};
|
||||
const isRefetching = response?.isRefetching;
|
||||
const isLoading = response?.isLoading;
|
||||
const dataLength = data?.length ;
|
||||
const {setDataTableLength} = useDataTableState()
|
||||
useEffect(() => {
|
||||
setDataTableLength(dataLength)
|
||||
}, [dataLength])
|
||||
|
||||
return (
|
||||
<Table
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { PaginationAntd, PaginationMeta } from "../../types/Table";
|
||||
import { useFilterStateState } from "../../zustand/Filter";
|
||||
|
||||
|
|
@ -8,8 +7,6 @@ interface Data {
|
|||
}
|
||||
|
||||
const usePagination = (data: Data) => {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { Filter ,setFilter } = useFilterStateState();
|
||||
|
||||
const [pagination, setPagination] = useState<PaginationAntd>({
|
||||
|
|
@ -29,7 +26,6 @@ const usePagination = (data: Data) => {
|
|||
}, [data]);
|
||||
|
||||
const handlePageChange = (page: number) => {
|
||||
// navigate(`?page=${page}`);
|
||||
setFilter({
|
||||
...Filter,
|
||||
page:page
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const SelectTag: React.FC = () => {
|
|||
const [fieldValue, setFieldValue] = useState<string>("");
|
||||
const formik = useFormikContext<any>();
|
||||
const handleChange = (value: string[]) => {
|
||||
console.log(value);
|
||||
console.log(value,"value");
|
||||
|
||||
formik.setFieldValue("tags", value);
|
||||
setSearchValue("");
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ const EditPage: React.FC = () => {
|
|||
const handleSubmit = (values: any) => {
|
||||
const DataToSend = structuredClone(values);
|
||||
setTagsSearch(null);
|
||||
console.log(DataToSend);
|
||||
|
||||
if (isBseQuestion) {
|
||||
const UpdateBseQuestion = {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ const Choices = () => {
|
|||
{formik?.values?.answers?.map((item: Choice, index: number) => {
|
||||
return (
|
||||
<div
|
||||
key={index}
|
||||
>
|
||||
<ChoiceFields index={index} data={item} />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ const Form = () => {
|
|||
setSavedQuestionData(formik.values);
|
||||
}, [formik?.values]);
|
||||
|
||||
// console.log(formik?.errors);
|
||||
|
||||
const handleAddChoice = (
|
||||
parent_index: number,
|
||||
fromKeyCombination: boolean = false,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
|
|||
|
||||
|
||||
const values = formik.values.Questions?.[index] ;
|
||||
console.log(values,"values");
|
||||
|
||||
const handelCanDeleteAnswers = ()=>{
|
||||
const content = values?.content ;
|
||||
|
|
|
|||
|
|
@ -49,14 +49,20 @@ const MaltySelectTag = ({ parent_index }: { parent_index: number }) => {
|
|||
options.length < 1 && searchValue.length > 1 && !isLoading
|
||||
? [{ id: searchValue, name: searchValue }]
|
||||
: [];
|
||||
console.log(formik?.values?.Questions[parent_index]?.tags,"formik?.values?.Questions[parent_index]?.tags");
|
||||
|
||||
const value =
|
||||
formik?.values?.Questions[parent_index]?.tags?.map(
|
||||
(item: any) => item?.id ?? item,
|
||||
) ?? [];
|
||||
|
||||
const AllOptions = [...options, ...additionalData,NewAdditionalData , ...(formik?.values?.Questions[parent_index]?.tags ?? [])];
|
||||
|
||||
const initialData = formik?.values?.Questions[parent_index]?.tags?.filter((item:any)=>{
|
||||
return item?.id
|
||||
|
||||
}) ?? []
|
||||
|
||||
|
||||
const AllOptions = [...options, ...additionalData,NewAdditionalData , ...(initialData)];
|
||||
|
||||
const uniqueOptions = Array.from(
|
||||
new Map(
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ const TableHeader = () => {
|
|||
{name:LessonName, path:`lesson/${lesson_id }`}
|
||||
]);
|
||||
|
||||
|
||||
return (
|
||||
<div className="TableWithHeader">
|
||||
<Suspense fallback={<Spin />}>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import * as Yup from "yup";
|
||||
import { Question } from "../../../types/Item";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
export const getInitialValues = (objectToEdit: Question): any => {
|
||||
const tags = objectToEdit?.tags?.map((item: any, index: number) => {
|
||||
|
|
@ -60,7 +59,6 @@ export const getInitialValuesBase = (objectToEdit: Question): any => {
|
|||
|
||||
}
|
||||
})
|
||||
console.log(newAnswers,"newAnswers");
|
||||
|
||||
return {
|
||||
...item,
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ function useAxios() {
|
|||
|
||||
build_Axios.interceptors.response.use(
|
||||
function (response: any) {
|
||||
console.log(response?.data);
|
||||
|
||||
const responseMsg = response?.data?.message;
|
||||
const method = response.config.method;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import { useMutation, UseMutationResult } from "react-query";
|
|||
import useAxios from "./useAxios";
|
||||
import { HEADER_KEY } from "../config";
|
||||
import { AxiosResponse } from "../../types/Axios";
|
||||
import { useDataTableState } from "../../zustand/TabState";
|
||||
import { useFilterStateState } from "../../zustand/Filter";
|
||||
|
||||
type DataToSend = {
|
||||
id?: number | string | any;
|
||||
|
|
@ -14,8 +16,12 @@ function useDeleteMutation(
|
|||
toast: boolean = true,
|
||||
): UseMutationResult<AxiosResponse, unknown, DataToSend, unknown> {
|
||||
const axios = useAxios();
|
||||
const {DataTableLength} = useDataTableState()
|
||||
const { setFilter ,Filter } = useFilterStateState();
|
||||
const page = Filter?.page ;
|
||||
return useMutation<AxiosResponse, unknown, DataToSend, unknown>(
|
||||
async (dataToSend) => {
|
||||
|
||||
const { data } = await axios.delete(url + `/` + dataToSend?.id, {
|
||||
headers: {
|
||||
[HEADER_KEY]: key,
|
||||
|
|
@ -25,7 +31,21 @@ function useDeleteMutation(
|
|||
|
||||
return data;
|
||||
},
|
||||
);
|
||||
{
|
||||
onSuccess : (data) =>{
|
||||
if(DataTableLength === 1 && page > 1){
|
||||
setFilter(
|
||||
{
|
||||
...Filter,
|
||||
page: page - 1
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
export default useDeleteMutation;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ interface ModelState {
|
|||
}
|
||||
|
||||
export const useObjectToEdit = create<ModelState>((set) => ({
|
||||
c: null,
|
||||
objectToEdit: null,
|
||||
setObjectToEdit: (data) => set(() => ({ objectToEdit: data })),
|
||||
OldObjectToEdit: null,
|
||||
setOldObjectToEdit: (data) => set(() => ({ OldObjectToEdit: data })),
|
||||
|
|
|
|||
12
src/zustand/TabState.ts
Normal file
12
src/zustand/TabState.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { create } from "zustand";
|
||||
|
||||
interface DataTableState {
|
||||
|
||||
DataTableLength: number;
|
||||
setDataTableLength: (Key: number) => void;
|
||||
}
|
||||
|
||||
export const useDataTableState = create<DataTableState>((set) => ({
|
||||
DataTableLength: 0,
|
||||
setDataTableLength: (Key) => set((state) => ({ DataTableLength: Key })),
|
||||
}));
|
||||
Loading…
Reference in New Issue
Block a user