fix: pass supply chain scope through sample editor
This commit is contained in:
parent
5984f82c75
commit
ecf4d4f743
@ -52,17 +52,19 @@ const parseDateInput = (value: string) => new Date(`${value}T12:00:00.000Z`)
|
||||
|
||||
type Props = {
|
||||
item: SampleProgressDTO | null
|
||||
permissionScope?: 'supply-chain'
|
||||
onClose: () => void
|
||||
onSaved: (item: SampleProgressDTO) => void
|
||||
}
|
||||
|
||||
export default function SampleProgressEditorDrawer({ item, onClose, onSaved }: Props) {
|
||||
export default function SampleProgressEditorDrawer({ item, permissionScope, onClose, onSaved }: Props) {
|
||||
const titleId = useId()
|
||||
const [draft, setDraft] = useState<SampleProgressUpdateInput>(() => item ? draftFromItem(item) : emptyDraft())
|
||||
const [oaReachedAt, setOaReachedAt] = useState<string | null>(item?.oaReachedAt ?? null)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [message, setMessage] = useState('')
|
||||
const [previewOpen, setPreviewOpen] = useState(false)
|
||||
const scopeQuery = permissionScope ? '?permissionScope=supply-chain' : ''
|
||||
|
||||
useEffect(() => {
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
@ -82,7 +84,7 @@ export default function SampleProgressEditorDrawer({ item, onClose, onSaved }: P
|
||||
|
||||
async function loadOaPrefill() {
|
||||
if (item || !draft.openingCode.trim()) return
|
||||
const response = await fetch(`/api/intake/sample-progress/oa-prefill?openingCode=${encodeURIComponent(draft.openingCode)}`)
|
||||
const response = await fetch(`/api/intake/sample-progress/oa-prefill?openingCode=${encodeURIComponent(draft.openingCode)}${permissionScope ? '&permissionScope=supply-chain' : ''}`)
|
||||
const result = await response.json()
|
||||
if (!response.ok) { setMessage(result?.error?.message || 'OA 数据读取失败'); return }
|
||||
const data = result.data as { brand: string; designer: string; imageUrl: string | null; oaReachedAt: string | null; purchaseOwner: string; merchandiserOwner: string }
|
||||
@ -103,7 +105,7 @@ export default function SampleProgressEditorDrawer({ item, onClose, onSaved }: P
|
||||
setSaving(true)
|
||||
setMessage('')
|
||||
try {
|
||||
const response = await fetch(item ? `/api/intake/sample-progress/${item.id}` : '/api/intake/sample-progress', {
|
||||
const response = await fetch(item ? `/api/intake/sample-progress/${item.id}${scopeQuery}` : `/api/intake/sample-progress${scopeQuery}`, {
|
||||
method: item ? 'PUT' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(draft),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user