Added base path
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
GroupSetFactoryArrayBody,
|
||||
SetFactoryArrayBody
|
||||
} from '../../src/types/ApiSchemasFrontend'
|
||||
import {NextRouter, useRouter} from 'next/router'
|
||||
|
||||
interface Props {
|
||||
children: ReactNodeLike
|
||||
@@ -91,8 +92,8 @@ interface StoredFile {
|
||||
excludedSuggestions: string[]
|
||||
}
|
||||
|
||||
export const postFetchJson = async (url: string, body: unknown) => {
|
||||
const res = await fetch(url, {
|
||||
export const postFetchJson = async (router: NextRouter, url: string, body: unknown) => {
|
||||
const res = await fetch(router.basePath+url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -103,6 +104,7 @@ export const postFetchJson = async (url: string, body: unknown) => {
|
||||
}
|
||||
|
||||
export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
||||
const router = useRouter()
|
||||
const [excludedSuggestions, _setExcludedSuggestions] = useState<string[]>(initial.ignored)
|
||||
const [basicValues, _setBasicValues] = useState<string[]>(initial.base)
|
||||
const [groups, setGroups] = useState<Dict<Group>>(initial.groups)
|
||||
@@ -122,7 +124,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
||||
const setExcludedSuggestions = useCallback<typeof _setExcludedSuggestions>(
|
||||
val => {
|
||||
_setExcludedSuggestions(val)
|
||||
postFetchJson(`/api/${fixedEncodeURIComponent(id)}/factories`, {
|
||||
postFetchJson(router, `/api/${fixedEncodeURIComponent(id)}/factories`, {
|
||||
type: 'ignored',
|
||||
factories: val
|
||||
} as SetFactoryArrayBody).catch(console.error)
|
||||
@@ -133,7 +135,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
||||
const setBasicValues = useCallback<typeof _setBasicValues>(
|
||||
val => {
|
||||
_setBasicValues(val)
|
||||
postFetchJson(`/api/${fixedEncodeURIComponent(id)}/factories`, {
|
||||
postFetchJson(router, `/api/${fixedEncodeURIComponent(id)}/factories`, {
|
||||
type: 'base',
|
||||
factories: val
|
||||
} as SetFactoryArrayBody).catch(console.error)
|
||||
@@ -151,11 +153,13 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
||||
})
|
||||
;(async () => {
|
||||
await postFetchJson(
|
||||
router,
|
||||
`/api/${fixedEncodeURIComponent(id)}/group/${fixedEncodeURIComponent(name)}/add`,
|
||||
{}
|
||||
)
|
||||
if (exports.length) {
|
||||
await postFetchJson(
|
||||
router,
|
||||
`/api/${fixedEncodeURIComponent(id)}/group/${fixedEncodeURIComponent(name)}/factories`,
|
||||
{
|
||||
type: 'exports',
|
||||
@@ -165,6 +169,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
||||
}
|
||||
if (malls.length) {
|
||||
await postFetchJson(
|
||||
router,
|
||||
`/api/${fixedEncodeURIComponent(id)}/group/${fixedEncodeURIComponent(name)}/factories`,
|
||||
{
|
||||
type: 'malls',
|
||||
@@ -185,6 +190,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
||||
return { ...g }
|
||||
})
|
||||
postFetchJson(
|
||||
router,
|
||||
`/api/${fixedEncodeURIComponent(id)}/group/${fixedEncodeURIComponent(name)}/remove`,
|
||||
{}
|
||||
).catch(console.error)
|
||||
@@ -202,6 +208,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
||||
return { ...g }
|
||||
})
|
||||
postFetchJson(
|
||||
router,
|
||||
`/api/${fixedEncodeURIComponent(id)}/group/${fixedEncodeURIComponent(name)}/rename`,
|
||||
{
|
||||
newName
|
||||
@@ -219,6 +226,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
||||
return { ...g }
|
||||
})
|
||||
postFetchJson(
|
||||
router,
|
||||
`/api/${fixedEncodeURIComponent(id)}/group/${fixedEncodeURIComponent(name)}/factories`,
|
||||
{
|
||||
type,
|
||||
|
||||
@@ -50,7 +50,7 @@ export const Home: FC = () => {
|
||||
Store
|
||||
</button>
|
||||
<button
|
||||
onClick={() => postFetchJson(`/api/${router.query.id}/upload`, { groups, ignored: ignoredFactories, base: baseFactories } as UploadDataBody)}
|
||||
onClick={() => postFetchJson(router, `/api/${router.query.id}/upload`, { groups, ignored: ignoredFactories, base: baseFactories } as UploadDataBody)}
|
||||
>
|
||||
Upload
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user