-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup details api called from service using store, and displayed data
- Loading branch information
Showing
6 changed files
with
101 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,4 +72,3 @@ export const updateCategoryForAdmin = (category_id, categoryData) => { | |
}; | ||
|
||
export default { }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// src/services/adminSetupAPI.js | ||
|
||
import axios from "axios"; | ||
import { API_BASE_URL } from "@/config"; | ||
import { refreshToken } from "@/services/refreshToken"; | ||
|
||
const apiClient = axios.create({ | ||
baseURL: API_BASE_URL, | ||
withCredentials: false, | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${localStorage.getItem("accessToken")}`, | ||
}, | ||
}); | ||
|
||
// Request interceptor to add the token | ||
apiClient.interceptors.request.use((config) => { | ||
const token = localStorage.getItem("accessToken"); | ||
if (token) { | ||
config.headers.Authorization = `Bearer ${token}`; | ||
} | ||
return config; | ||
}, (error) => { | ||
return Promise.reject(error); | ||
}); | ||
|
||
// Response interceptor to handle errors | ||
apiClient.interceptors.response.use( | ||
(response) => response, | ||
async (error) => { | ||
if (error.response.status === 401) { | ||
// Handle unauthorized error (e.g., refresh token or redirect to login) | ||
try { | ||
await refreshToken(); | ||
return apiClient(error.config); // Retry the original request | ||
} catch (refreshError) { | ||
localStorage.removeItem("accessToken"); | ||
window.location.href = "/login"; // Redirect to login page | ||
} | ||
} | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
export const getSetupForAdmin = () => { | ||
return apiClient.get(`/api/v1/configures/setup`); | ||
}; | ||
|
||
export default {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// /src/store/modules/setup.js | ||
|
||
import { | ||
getSetupForAdmin, | ||
} from "@/services/adminSetupAPI"; | ||
|
||
const state = { | ||
setup: {}, | ||
}; | ||
|
||
const mutations = { | ||
setSetup(state, setup) { | ||
state.setup = setup; | ||
}, | ||
}; | ||
|
||
const actions = { | ||
async fetchSetup({ commit }) { | ||
const response = await getSetupForAdmin(); | ||
commit("setSetup", response.data); | ||
}, | ||
}; | ||
|
||
const getters = { | ||
setup: (state) => state.setup, | ||
}; | ||
|
||
export default { | ||
namespaced: true, | ||
state, | ||
mutations, | ||
actions, | ||
getters, | ||
}; |