use axiosInstance
inside of LinkedItems
component
This commit is contained in:
parent
b4afcdfa3b
commit
f649b1390e
@ -1,7 +1,7 @@
|
|||||||
import {useState, useEffect} from 'react'
|
import {useState, useEffect} from 'react'
|
||||||
import {Stack, Typography, Button, FormControl, Grid, Box, Accordion, AccordionSummary, AccordionDetails, useTheme, TextField, Autocomplete} from '@mui/material'
|
import {Stack, Typography, Button, FormControl, Grid, Box, Accordion, AccordionSummary, AccordionDetails, useTheme, TextField, Autocomplete} from '@mui/material'
|
||||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
|
||||||
import axios from 'axios'
|
import {axiosInstance} from '../providers/data'
|
||||||
import {BACKEND_URL} from '../lib/constants'
|
import {BACKEND_URL} from '../lib/constants'
|
||||||
import {Link} from 'react-router'
|
import {Link} from 'react-router'
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ export const LinkedItems = <T extends {id: number; [key: string]: any}>({parentI
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (parentId) {
|
if (parentId) {
|
||||||
axios
|
axiosInstance
|
||||||
.get(`${BACKEND_URL}/${parentResource}/${parentId}/${childResource}`)
|
.get(`${BACKEND_URL}/${parentResource}/${parentId}/${childResource}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setLinkedItems(response?.data || [])
|
setLinkedItems(response?.data || [])
|
||||||
@ -51,7 +51,7 @@ export const LinkedItems = <T extends {id: number; [key: string]: any}>({parentI
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (type === 'edit') {
|
if (type === 'edit') {
|
||||||
axios
|
axiosInstance
|
||||||
.get(`${BACKEND_URL}/${childResource}/`)
|
.get(`${BACKEND_URL}/${childResource}/`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setItems(response?.data || [])
|
setItems(response?.data || [])
|
||||||
@ -91,10 +91,10 @@ export const LinkedItems = <T extends {id: number; [key: string]: any}>({parentI
|
|||||||
[`${childResource}_id`]: selectedItemId,
|
[`${childResource}_id`]: selectedItemId,
|
||||||
}
|
}
|
||||||
|
|
||||||
axios
|
axiosInstance
|
||||||
.post(`${BACKEND_URL}/${parentResource}/${parentId}/${childResource}`, requestData)
|
.post(`${BACKEND_URL}/${parentResource}/${parentId}/${childResource}`, requestData)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
axios.get(`${BACKEND_URL}/${parentResource}/${parentId}/${childResource}`).then((response) => {
|
axiosInstance.get(`${BACKEND_URL}/${parentResource}/${parentId}/${childResource}`).then((response) => {
|
||||||
setLinkedItems(response?.data || [])
|
setLinkedItems(response?.data || [])
|
||||||
setSelectedItemId(null)
|
setSelectedItemId(null)
|
||||||
if (childResource === 'article') {
|
if (childResource === 'article') {
|
||||||
@ -109,7 +109,7 @@ export const LinkedItems = <T extends {id: number; [key: string]: any}>({parentI
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deleteItem = (itemId: number) => {
|
const deleteItem = (itemId: number) => {
|
||||||
axios
|
axiosInstance
|
||||||
.delete(`${BACKEND_URL}/${parentResource}/${parentId}/${childResource}`, {
|
.delete(`${BACKEND_URL}/${parentResource}/${parentId}/${childResource}`, {
|
||||||
data: {[`${childResource}_id`]: itemId},
|
data: {[`${childResource}_id`]: itemId},
|
||||||
})
|
})
|
||||||
|
@ -4,7 +4,7 @@ import {BACKEND_URL} from '../lib/constants'
|
|||||||
import {TOKEN_KEY} from '../authProvider'
|
import {TOKEN_KEY} from '../authProvider'
|
||||||
import Cookies from 'js-cookie'
|
import Cookies from 'js-cookie'
|
||||||
|
|
||||||
const axiosInstance = axios.create()
|
export const axiosInstance = axios.create()
|
||||||
|
|
||||||
axiosInstance.interceptors.request.use((config) => {
|
axiosInstance.interceptors.request.use((config) => {
|
||||||
// Добавляем токен авторизации
|
// Добавляем токен авторизации
|
||||||
|
Loading…
Reference in New Issue
Block a user