fixing media URL

This commit is contained in:
Dimas Atmodjo 2024-11-19 23:02:04 +07:00
parent 1a5cddd922
commit 92ccf51cf2
14 changed files with 44 additions and 42 deletions

View File

@ -1,6 +1,6 @@
import { useState, useEffect, useRef } from 'react';
import exerciseService from '../services/serviceExercises';
import { API_URL } from '../../../../utils/Constant';
import { MEDIA_URL } from '../../../../utils/Constant';
function videoUrlChecker(url) {
const youtubeRegex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
@ -23,7 +23,7 @@ const useUpdateExercises = (levelId) => {
const [topicName, setTopicName] = useState('topic');
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const mediaPath = `${API_URL}/uploads/exercise`;
const mediaPath = `${MEDIA_URL}/uploads/exercise`;
const [formData, setFormData] = useState({
ID_ADMIN_EXERCISE: "",

View File

@ -1,7 +1,7 @@
import { useState, useEffect, useRef } from 'react';
import materialService from '../services/serviceMaterials';
import { ButtonView } from 'ckeditor5';
import { API_URL } from '../../../../utils/Constant';
import { MEDIA_URL } from '../../../../utils/Constant';
const useTest = (materialId) => {
const [editorData, setEditorData] = useState('');
@ -13,7 +13,7 @@ const useTest = (materialId) => {
const editorContainerRef = useRef(null);
const editorRef = useRef(null);
const [isLayoutReady, setIsLayoutReady] = useState(false);
const mediaPath = `${API_URL}/uploads/level/`;
const mediaPath = `${MEDIA_URL}/uploads/level/`;
const [show, setShow] = useState(false);

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import materialService from '../services/serviceMaterials';
import { API_URL } from '../../../../utils/Constant';
import { MEDIA_URL } from '../../../../utils/Constant';
const useUpdateMaterials = (materialId) => {
const [materialData, setMaterialData] = useState([]);
@ -9,7 +9,7 @@ const useUpdateMaterials = (materialId) => {
const [topicName, setTopicName] = useState('topic');
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const mediaPath = `${API_URL}/uploads/level`;
const mediaPath = `${MEDIA_URL}/uploads/level`;
const [formData, setFormData] = useState({
content: '',

View File

@ -1,9 +1,9 @@
import { useState, useEffect } from 'react';
import sectionService from '../services/serviceSections';
import { API_URL } from '../../../../utils/Constant';
import { MEDIA_URL } from '../../../../utils/Constant';
const useSections = () => {
const thumbPath = `${API_URL}/uploads/section/`;
const thumbPath = `${MEDIA_URL}/uploads/section/`;
const [sections, setSections] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);

View File

@ -102,12 +102,14 @@ const ManageSections = () => {
<td>{section.NAME_SECTION}</td>
<td>{section.DESCRIPTION_SECTION}</td>
<td className='text-center action-col'>
<Button size='sm' className='btn-edit' onClick={() => handleShow(section)}>
<i className="bi bi-pencil-square"></i>
</Button>
<Button size='sm' className='btn-delete' onClick={() => deleteSection(section.ID_SECTION)}>
<i className="bi bi-trash3"></i>
</Button>
<div className="d-flex">
<Button size='sm' className='btn-edit' onClick={() => handleShow(section)}>
<i className="bi bi-pencil-square"></i>
</Button>
<Button size='sm' className='btn-delete' onClick={() => deleteSection(section.ID_SECTION)}>
<i className="bi bi-trash3"></i>
</Button>
</div>
</td>
</tr>
))

View File

@ -108,12 +108,14 @@ const ManageTopics = () => {
<td>{topic.NAME_TOPIC}</td>
<td>{topic.DESCRIPTION_TOPIC}</td>
<td className='text-center action-col'>
<Button size='sm' className='btn-edit' onClick={() => handleShow(topic)}>
<i className="bi bi-pencil-square"></i>
</Button>
<Button size='sm' className='btn-delete' onClick={() => deleteTopic(topic.ID_TOPIC)}>
<i className="bi bi-trash3"></i>
</Button>
<div class="d-flex">
<Button size='sm' className='btn-edit' onClick={() => handleShow(topic)}>
<i className="bi bi-pencil-square"></i>
</Button>
<Button size='sm' className='btn-delete' onClick={() => deleteTopic(topic.ID_TOPIC)}>
<i className="bi bi-trash3"></i>
</Button>
</div>
</td>
</tr>
))

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import settingService from '../services/SettingService';
import { API_URL } from '../../../../utils/Constant';
import { MEDIA_URL } from '../../../../utils/Constant';
const useSettings = () => {
const [profile, setProfile] = useState(null);
@ -10,7 +10,7 @@ const useSettings = () => {
const [loadingUpdate, setLoadingUpdate] = useState(false);
const [error, setError] = useState(null);
const [success, setSuccess] = useState(false);
const thumbPath = `${API_URL}/uploads/avatar/`;
const thumbPath = `${MEDIA_URL}/uploads/avatar/`;
useEffect(() => {
const fetchData = async () => {

View File

@ -5,7 +5,7 @@ import { API_URL } from '../../../../utils/Constant';
// const login = async (EMAIL, PASSWORD) => {
// try {
// const response = await axios.post(`${API_URL}/api/login`, { EMAIL, PASSWORD });
// const response = await axios.post(`${API_URL}/login`, { EMAIL, PASSWORD });
// return response.data.payload;
// } catch (error) {
// throw new Error(error.response?.data?.message || 'Login failed');
@ -14,7 +14,7 @@ import { API_URL } from '../../../../utils/Constant';
const login = async (EMAIL, PASSWORD) => {
try {
const response = await axios.post(`${API_URL}/api/login`, { EMAIL, PASSWORD }, {
const response = await axios.post(`${API_URL}/login`, { EMAIL, PASSWORD }, {
withCredentials: true
});
const { TOKEN, refreshToken } = response.data.payload;
@ -25,7 +25,7 @@ const login = async (EMAIL, PASSWORD) => {
Authorization: TOKEN
}
};
const data = await axios.get(`${API_URL}/api/getMe`, config);
const data = await axios.get(`${API_URL}/getMe`, config);
const profile = data.data.payload;
localStorage.setItem('userData', JSON.stringify({username: profile.NAME_USERS, picture: profile.PICTURE}));
@ -37,7 +37,7 @@ const login = async (EMAIL, PASSWORD) => {
const register = async (endpoint, data) => {
try {
const response = await axios.post(`${API_URL}/api/register/${endpoint}`, data);
const response = await axios.post(`${API_URL}/register/${endpoint}`, data);
return response.data;
} catch (error) {
throw new Error(error.response?.data?.message || 'Registration failed');
@ -46,7 +46,7 @@ const register = async (endpoint, data) => {
const forgotPassword = async (email) => {
try {
const response = await axios.post(`${API_URL}/api/forgot-password`, { email });
const response = await axios.post(`${API_URL}/forgot-password`, { email });
return response.data;
} catch (error) {
throw new Error(error.response?.data?.message || 'Password reset failed');
@ -60,7 +60,7 @@ const logout = () => {
const validateEmail = async (TOKEN) => {
try {
const response = await axios.post(`${API_URL}/api/validateEmail`, { TOKEN });
const response = await axios.post(`${API_URL}/validateEmail`, { TOKEN });
return response.data;
} catch (error) {
throw new Error(error.response?.data?.message || 'Failed Validate');

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import settingService from '../services/SettingService';
import { API_URL } from '../../../../utils/Constant';
import { MEDIA_URL } from '../../../../utils/Constant';
const useSettings = () => {
const [profile, setProfile] = useState(null);
@ -10,7 +10,7 @@ const useSettings = () => {
const [loadingUpdate, setLoadingUpdate] = useState(false);
const [error, setError] = useState(null);
const [success, setSuccess] = useState(false);
const thumbPath = `${API_URL}/uploads/avatar/`;
const thumbPath = `${MEDIA_URL}/uploads/avatar/`;
useEffect(() => {
const fetchData = async () => {

View File

@ -1,12 +1,12 @@
import { useState, useEffect } from 'react';
import homeService from '../services/dashboardService';
import { API_URL } from '../../../../utils/Constant';
import { MEDIA_URL } from '../../../../utils/Constant';
const useDashboards = () => {
const [journey, setJourney] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const thumbPath = `${API_URL}/uploads/section/`;
const thumbPath = `${MEDIA_URL}/uploads/section/`;
useEffect(() => {
const fetchData = async () => {

View File

@ -1,12 +1,12 @@
import { useState, useEffect } from 'react';
import learningService from '../services/learningService';
import { API_URL } from '../../../../utils/Constant';
import { MEDIA_URL } from '../../../../utils/Constant';
const useSections = () => {
const [sections, setSections] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const thumbPath = `${API_URL}/uploads/section/`;
const thumbPath = `${MEDIA_URL}/uploads/section/`;
useEffect(() => {
const fetchData = async () => {

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import settingService from '../services/SettingService';
import { API_URL } from '../../../../utils/Constant';
import { MEDIA_URL } from '../../../../utils/Constant';
const useSettings = () => {
const [profile, setProfile] = useState(null);
@ -10,7 +10,7 @@ const useSettings = () => {
const [loadingUpdate, setLoadingUpdate] = useState(false);
const [error, setError] = useState(null);
const [success, setSuccess] = useState(false);
const thumbPath = `${API_URL}/uploads/avatar/`;
const thumbPath = `${MEDIA_URL}/uploads/avatar/`;
useEffect(() => {
const fetchData = async () => {

View File

@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import topicService from '../services/topicService';
import { API_URL } from '../../../../utils/Constant';
import { MEDIA_URL } from '../../../../utils/Constant';
import { useSlugContext } from '../../../../utils/SlugContext';
const useTopics = (sectionId) => {
@ -8,7 +8,7 @@ const useTopics = (sectionId) => {
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const [sections, setSection] = useState(null);
const thumbPath = `${API_URL}/uploads/section/`;
const thumbPath = `${MEDIA_URL}/uploads/section/`;
const { sectionSlugMap } = useSlugContext();
useEffect(() => {

View File

@ -1,10 +1,8 @@
import axios from 'axios';
import { API_URL } from './Constant';
const URL_API = `${API_URL}/api`
const axiosInstance = axios.create({
baseURL: URL_API,
baseURL: API_URL,
});
axiosInstance.interceptors.request.use(
@ -22,7 +20,7 @@ axiosInstance.interceptors.request.use(
const refreshAccessToken = async () => {
try {
const response = await axios.post(`${URL_API}/refreshToken`, {}, { withCredentials: true });
const response = await axios.post(`${API_URL}/refreshToken`, {}, { withCredentials: true });
const token = response.data.payload.TOKEN;
localStorage.setItem('token', token);