Compare commits

..

2 Commits

Author SHA1 Message Date
karimalden
fad0d81565 end 2024-07-03 21:36:56 +03:00
karimalden
b34ba269c1 dix_error_add_empty_tag 2024-06-29 12:11:32 +03:00
7 changed files with 64 additions and 32 deletions

View File

@ -0,0 +1,32 @@
import { useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
const usePreviousPath = () => {
const location = useLocation();
const navigate = useNavigate();
const [previousPath, setPreviousPath] = useState(null);
console.log(previousPath);
useEffect(() => {
// Update the previous path whenever the location changes
const currentPath = location.pathname as any;
setPreviousPath(currentPath);
// Clean up
return () => {
setPreviousPath(null);
};
}, [location]);
const navigateToPreviousPath = () => {
if (previousPath) {
navigate(previousPath);
} else {
navigate(-1); // Fallback to default behavior
}
};
return { navigateToPreviousPath };
};
export default usePreviousPath;

View File

@ -15,6 +15,9 @@ import { ModalEnum } from "../../enums/Model";
import ChangePasswordModel from "./model/AddModel"; import ChangePasswordModel from "./model/AddModel";
import { getLocalStorage } from "../../utils/LocalStorage"; import { getLocalStorage } from "../../utils/LocalStorage";
import NavBarSelect from "../../Components/Layout/NavBarSelect"; import NavBarSelect from "../../Components/Layout/NavBarSelect";
import usePreviousRoute from "../../Hooks/usePreviousRoute";
import usePreviousPath from "../../Hooks/usePreviousRoute";
import { useLocationsState } from "../../zustand/Location";
const NavBar = () => { const NavBar = () => {
const { Page_title } = usePage_titleState((state) => state); const { Page_title } = usePage_titleState((state) => state);
const userData = getLocalStorage(USER_KEY); const userData = getLocalStorage(USER_KEY);
@ -25,19 +28,20 @@ const NavBar = () => {
const translateArray = translateOptions(search_array, t); const translateArray = translateOptions(search_array, t);
const { course_id } = useParams<ParamsEnum>(); const { course_id } = useParams<ParamsEnum>();
console.log(location); console.log(location);
const {PreLocation} = useLocationsState()
const navigate = useNavigate(); const navigate = useNavigate();
const handelNavigate = () => { const handelNavigate = () => {
const pattern = /^\/course\/\d+\/eduClass\/\d+$/; const pattern = /^\/course\/\d+\/eduClass\/\d+$/;
if (pattern.test(location.pathname)) { if (pattern.test(location.pathname)) {
navigate(`/course/${course_id}/eduClass`); navigate(`/course/${course_id}/eduClass`);
return; return;
}else if (PreLocation) {
navigate(PreLocation)
}else{
navigate(-1)
} }
if (location.pathname === "/") {
return;
}
navigate(-1);
}; };
const { handel_open_model } = useModalHandler(); const { handel_open_model } = useModalHandler();

View File

@ -12,7 +12,6 @@ import Header from "../../Components/exercise/Header";
import { Question } from "../../types/Item"; import { Question } from "../../types/Item";
import BaseForm from './Model/Malty/Add' import BaseForm from './Model/Malty/Add'
import Form from './Model/Add' import Form from './Model/Add'
import { toast } from "react-toastify";
const AcceptModal = lazy(() => import('./Model/AcceptModal')); const AcceptModal = lazy(() => import('./Model/AcceptModal'));
import { useModalState } from "../../zustand/Modal"; import { useModalState } from "../../zustand/Modal";
@ -22,6 +21,7 @@ import { hasItems } from "../../utils/hasItems";
import { QUESTION_OBJECT_KEY } from "../../config/AppKey"; import { QUESTION_OBJECT_KEY } from "../../config/AppKey";
import useSaveOnDisconnect from "../../Hooks/useSaveOnDisconnect"; import useSaveOnDisconnect from "../../Hooks/useSaveOnDisconnect";
import { getLocalStorageQuestions } from "../../utils/setLocalStorageQuestions"; import { getLocalStorageQuestions } from "../../utils/setLocalStorageQuestions";
import { toast } from "react-toastify";
const AddPage: React.FC = () => { const AddPage: React.FC = () => {
@ -82,13 +82,19 @@ const AddPage: React.FC = () => {
useEffect(() => { useEffect(() => {
if (isSuccessAsync && ( SavedQuestionData?.Questions?.length > 0 ? isSuccess: true )) { if (isSuccessAsync && ( SavedQuestionData?.Questions?.length > 0 ? isSuccess: true )) {
set_object_to_edit(null) set_object_to_edit(null)
set_Success(true) set_Success(true)
localStorage.removeItem(QUESTION_OBJECT_KEY) localStorage.removeItem(QUESTION_OBJECT_KEY)
} }
if(isSuccess && !(SavedQuestionData?.Questions?.length)){
toast.success(t("validation.the_possess_done_successful"))
set_object_to_edit(null)
set_Success(true)
localStorage.removeItem(QUESTION_OBJECT_KEY)
}
}, [isSuccess,isSuccessAsync]) }, [isSuccess,isSuccessAsync])
let cleanedQuestionOptions = cleanObject(SavedQuestionData); let cleanedQuestionOptions = cleanObject(SavedQuestionData);
@ -100,7 +106,6 @@ const AddPage: React.FC = () => {
const SavedData = getLocalStorageQuestions(QUESTION_OBJECT_KEY) const SavedData = getLocalStorageQuestions(QUESTION_OBJECT_KEY)
console.log(SavedData);
const handleCancel = () => { const handleCancel = () => {
if(!noChange){ if(!noChange){
navigate(-1) navigate(-1)
@ -114,7 +119,6 @@ const AddPage: React.FC = () => {
const [t] = useTranslation(); const [t] = useTranslation();
console.log(SavedData?.isBase === 1);
if(isBseQuestion || SavedData?.isBase === 1){ if(isBseQuestion || SavedData?.isBase === 1){

View File

@ -104,7 +104,7 @@ export function processTags(DataToSend: any) {
}).filter((item:any) => item !== undefined); }).filter((item:any) => item !== undefined);
const newTags = DataToSend?.tags?.map((item: any, index: number) => { const newTags = DataToSend?.tags?.map((item: any, index: number) => {
if (typeof item?.id === "string") { if (typeof item?.id === "string" && item?.name !== "" ) {
return { name: item?.name }; return { name: item?.name };
} }
}).filter((item:any) => item !== undefined); }).filter((item:any) => item !== undefined);

View File

@ -102,27 +102,7 @@ export const CrudRoute: TCrudRoute[] = [
abilities: ABILITIES_ENUM?.QUESTION, abilities: ABILITIES_ENUM?.QUESTION,
abilities_value: ABILITIES_VALUES_ENUM.INDEX, abilities_value: ABILITIES_VALUES_ENUM.INDEX,
}, },
// {
// header: "page_header.Question_child",
// element: <QuestionChildren />,
// path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/:${ParamsEnum?.CHILDREN_QUESTION_ID}/children`,
// abilities: ABILITIES_ENUM?.QUESTION,
// abilities_value: ABILITIES_VALUES_ENUM.INDEX,
// },
// {
// header: "page_header.add_Question_child",
// element: <AddQuestionChildren />,
// path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/:${ParamsEnum?.CHILDREN_QUESTION_ID}/children/add`,
// abilities: ABILITIES_ENUM?.QUESTION,
// abilities_value: ABILITIES_VALUES_ENUM.INDEX,
// },
// {
// header: "page_header.edit_Question_child",
// element: <EditQuestionChildren />,
// path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/:${ParamsEnum?.CHILDREN_QUESTION_ID}/children/:${ParamsEnum?.CHILDREN_QUESTION_ID}`,
// abilities: ABILITIES_ENUM?.QUESTION,
// abilities_value: ABILITIES_VALUES_ENUM.INDEX,
// },
]; ];

View File

@ -1,4 +1,4 @@
// export const BaseURL = "http://192.168.1.108:8000/api/"; // export const BaseURL = "http://192.168.1.109:8000/api/";
// export const BaseURL = "http://127.0.0.1:8000/api/"; // export const BaseURL = "http://127.0.0.1:8000/api/";
export const BaseURL = "https://exercise-automation.point-dev.net/api/"; export const BaseURL = "https://exercise-automation.point-dev.net/api/";

12
src/zustand/Location.ts Normal file
View File

@ -0,0 +1,12 @@
import { create } from "zustand";
import { ModalEnum } from "../enums/Model";
interface LocationsState{
PreLocation: string;
setPreLocation: (value: string) => void;
}
export const useLocationsState= create<LocationsState>((set) => ({
PreLocation: "",
setPreLocation: (value: string) => set((state) => ({ PreLocation: value })),
}));