diff --git a/src/components/modals/module.tsx b/src/components/modals/module.tsx index 7cb4e9162c7a53d1bf20d0dadd8ab0a8176f35c1..40be522ee725d014bf209c71905f903b7c6de66d 100644 --- a/src/components/modals/module.tsx +++ b/src/components/modals/module.tsx @@ -214,7 +214,7 @@ export function EditModuleModal({ setEditedDescription(res.data.data.description); setTitle(res.data.data.title); setDescription(res.data.data.description); - } else { } + } setIsLoading(false); } catch (error) { console.error('Error fetching module data:', error); diff --git a/src/pages/Materials.tsx b/src/pages/Materials.tsx index 6e1a7d0130195cfa5cb6f5ebfdc4a488927d27b3..69fae44add35d9aafc866d4b619825e9fdf31d18 100644 --- a/src/pages/Materials.tsx +++ b/src/pages/Materials.tsx @@ -24,7 +24,7 @@ import { BiSolidTrash, BiPlusCircle, } from "react-icons/bi"; -import { useParams } from "react-router-dom"; +import { useNavigate, useParams } from "react-router-dom"; import { Modules, Materials } from "../types"; import { EditModuleModal, @@ -46,6 +46,7 @@ import "pdfjs-dist/build/pdf.worker.entry"; import Loading from "../components/loading/Loading"; const ModuleMaterials = () => { + const navigate = useNavigate(); const { course_id } = useParams(); const [course_id_int, setCourseIDInt] = useState(0); const [isLoading, setIsLoading] = useState(false); @@ -66,6 +67,10 @@ const ModuleMaterials = () => { const res = await newAxiosInstance.get( `${config.REST_API_URL}/modul/course/${course_id}` ); + const {status,data} = res ["data"]; + if(status !== 200){ + navigate("/not-found"); + } const ModulesData: Modules[] = res.data.data.map((module: any) => { return { id: module.id, diff --git a/src/pages/Profile.tsx b/src/pages/Profile.tsx index 400065fc8e9e02bbb69e4ac4bc6a103a89bfdb7e..28cf1882fcaff1861a74a87c3762dd0ee75b075c 100644 --- a/src/pages/Profile.tsx +++ b/src/pages/Profile.tsx @@ -141,7 +141,6 @@ function Profile() { // Dihapus cuma kalau adaa file pengganti dia if (oldImagePath && filepath) { // Kalau ada gambar lama, minta hapus - console.log('Masuk ke hapus'); axiosInstance .delete(`${config.REST_API_URL}/user/image/${oldImagePath}`) .then((res) => console.log(res)) diff --git a/src/pages/admin/PremiumUsers.tsx b/src/pages/admin/PremiumUsers.tsx index 46ec4b44ec59c4a58b70288d1c3ccc5a0c4227a6..255232ee62ab295eb1639e9ffb9ccb2b52d85774 100644 --- a/src/pages/admin/PremiumUsers.tsx +++ b/src/pages/admin/PremiumUsers.tsx @@ -58,17 +58,6 @@ const UsersList = () => { setIsLoading(true); const res = await newAxiosInstance.get(`${config.REST_API_URL}/user?page=${pageNumber}`); const { status } = res["data"]; - // if (status === 401) { - // toast({ - // title: "Unauthorized user", - // description: "You have to log in", - // status: "error", - // duration: 3000, - // isClosable: true, - // position: "top" - // }) - // navigate("/login"); - // } setTotalPages(Math.ceil(res.data.total / n)); const usersData: Users[] = res.data.data.map((user: any) => { diff --git a/src/utils/axios.ts b/src/utils/axios.ts index 98818f7129bceb46a011fb1b6cde775fabc09eea..7aef6cabc916fc72061ec9372f0f4c6bc45bd896 100644 --- a/src/utils/axios.ts +++ b/src/utils/axios.ts @@ -5,8 +5,7 @@ const BACKEND_REST_API_URL = process.env.REST_URL; const axiosInstance = axios.create({ baseURL: BACKEND_REST_API_URL, headers: { - // Authorization: `Bearer ${localStorage.getItem("token")}`, - // 'Access-Control-Allow-Credentials': 'true', + "X-API-KEY":"ReactApp", 'Access-Control-Allow-Origin': '*', }, withCredentials: true, @@ -16,8 +15,7 @@ const axiosConfig = () => { return { baseURL: BACKEND_REST_API_URL, headers: { - // Authorization: `Bearer ${localStorage.getItem("token")}`, - // 'Access-Control-Allow-Credentials': 'true', + "X-API-KEY" : "ReactApp", 'Access-Control-Allow-Origin': '*', }, withCredentials: true,