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