Skip to content

Commit

Permalink
fix: infer schema domain from token
Browse files Browse the repository at this point in the history
  • Loading branch information
gciotola committed Dec 17, 2024
1 parent e9ec172 commit 2d4de6f
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useTokenProvider } from '#providers/TokenProvider'
import {
InputWrapper,
type InputWrapperBaseProps
Expand Down Expand Up @@ -74,6 +75,9 @@ export const CodeEditor = forwardRef<HTMLInputElement, CodeEditorProps>(
const monaco = useMonaco()
const disposeCompletionItemProvider = useRef<() => void>()
const [editor, setEditor] = useState<Parameters<OnMount>[0] | null>(null)
const {
settings: { domain }
} = useTokenProvider()

const handleEditorDidMount: OnMount = (editor, monaco) => {
setEditor(editor)
Expand Down Expand Up @@ -119,7 +123,7 @@ export const CodeEditor = forwardRef<HTMLInputElement, CodeEditorProps>(
case 'organization-config': {
schemas.push({
schema: await fetch(
'https://provisioning.commercelayer.io/api/public/schemas/organization_config'
`https://provisioning.${domain}/api/public/schemas/organization_config`
)
.then<JsonValue>(async (res) => await res.json())
.then((json) => {
Expand All @@ -135,7 +139,7 @@ export const CodeEditor = forwardRef<HTMLInputElement, CodeEditorProps>(
case 'order-rules': {
schemas.push({
schema: await fetch(
'https://core.commercelayer.io/api/public/schemas/order_rules'
`https://core.${domain}/api/public/schemas/order_rules`
)
.then<JsonValue>(async (res) => await res.json())
.then((json) => {
Expand All @@ -154,7 +158,7 @@ export const CodeEditor = forwardRef<HTMLInputElement, CodeEditorProps>(
case 'price-rules': {
schemas.push({
schema: await fetch(
'https://core.commercelayer.io/api/public/schemas/price_rules'
`https://core.${domain}/api/public/schemas/price_rules`
)
.then<JsonValue>(async (res) => await res.json())
.then((json) => {
Expand Down Expand Up @@ -184,7 +188,7 @@ export const CodeEditor = forwardRef<HTMLInputElement, CodeEditorProps>(
return () => {
disposeCompletionItemProvider.current?.()
}
}, [monaco, editor, jsonSchema])
}, [monaco, editor, jsonSchema, domain])

return (
<InputWrapper
Expand Down

0 comments on commit 2d4de6f

Please sign in to comment.