@huaqiu/dsh-hardware-ui 0.7.19 → 0.7.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +851 -219
- package/lib/client.js.map +1 -1
- package/package.json +1 -1
- package/src/client/components.tsx +3 -0
- package/src/client/copy.ts +53 -13
- package/src/client/index.ts +77 -0
- package/src/client/locales.ts +63 -26
- package/src/client/model.ts +40 -0
- package/src/client/order.tsx +423 -453
- package/src/client/place-order.tsx +275 -0
- package/src/client/preview.tsx +4 -1
- package/src/client/store.ts +3 -0
- package/src/client/toolchain-view.tsx +90 -17
- package/src/client/toolchain.ts +173 -3
- package/src/client/transport.ts +4 -4
- package/src/client/wizard.tsx +16 -11
package/src/client/order.tsx
CHANGED
|
@@ -1,453 +1,423 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Order Placing destination.
|
|
3
|
-
*
|
|
4
|
-
* The panel never prices anything and never keeps its own order backend. It
|
|
5
|
-
* prepares the fabrication package with `kicad-cli` through the host, shows
|
|
6
|
-
* exactly
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
readonly
|
|
24
|
-
readonly
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
readonly
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
border:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** One workflow card: what it will do, what it needs, and its action. */
|
|
81
|
-
function workflowCard(input: {
|
|
82
|
-
readonly tag: string
|
|
83
|
-
readonly tagColor: string
|
|
84
|
-
readonly title: string
|
|
85
|
-
readonly subtitle: string
|
|
86
|
-
readonly details: readonly { label: string; value: string }[]
|
|
87
|
-
readonly action: string
|
|
88
|
-
readonly onAction: () => void
|
|
89
|
-
readonly busy: boolean
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
'
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
const [
|
|
135
|
-
const [
|
|
136
|
-
const [
|
|
137
|
-
const [
|
|
138
|
-
const [
|
|
139
|
-
const [
|
|
140
|
-
const [
|
|
141
|
-
const [
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
useEffect(() => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
'
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
:
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
style:
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
{ label: COPY.order.
|
|
310
|
-
|
|
311
|
-
action: COPY.order.
|
|
312
|
-
onAction: () => {
|
|
313
|
-
busy: placing === '
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
:
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
createElement('
|
|
347
|
-
|
|
348
|
-
'
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
'
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
...(message === undefined ? [] : [createElement('p', {
|
|
425
|
-
key: 'message', role: 'status', style: { ...MUTED, color: C.warn, borderLeft: `2px solid ${C.warn}`, paddingLeft: 8 },
|
|
426
|
-
}, message)]),
|
|
427
|
-
createElement(
|
|
428
|
-
'div',
|
|
429
|
-
{ style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(250px, 1fr))', gap: 10 } },
|
|
430
|
-
pcbCard,
|
|
431
|
-
smtCard,
|
|
432
|
-
),
|
|
433
|
-
createElement(
|
|
434
|
-
'div',
|
|
435
|
-
{ style: { ...SPREAD, ...cardStyle({ flexDirection: 'row', alignItems: 'center' }) } },
|
|
436
|
-
createElement('span', { style: { fontSize: 11, color: C.text2 } }, COPY.order.batch),
|
|
437
|
-
createElement(
|
|
438
|
-
'select',
|
|
439
|
-
{
|
|
440
|
-
style: { ...SELECT, width: 'auto' }, value: quantity,
|
|
441
|
-
'data-hardware-order-quantity': true,
|
|
442
|
-
onChange: (event: { currentTarget: HTMLSelectElement }) => { setQuantity(Number(event.currentTarget.value)) },
|
|
443
|
-
},
|
|
444
|
-
...QUANTITIES.map(count => createElement('option', { key: count, value: count }, COPY.order.batchUnits(count))),
|
|
445
|
-
),
|
|
446
|
-
createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } }, COPY.order.quoteBasis(quantity)),
|
|
447
|
-
),
|
|
448
|
-
packageCard,
|
|
449
|
-
resultCard,
|
|
450
|
-
agentHint,
|
|
451
|
-
dialog,
|
|
452
|
-
)
|
|
453
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Order Placing destination.
|
|
3
|
+
*
|
|
4
|
+
* The panel never prices anything and never keeps its own order backend. It
|
|
5
|
+
* prepares the fabrication package with `kicad-cli` through the host, shows
|
|
6
|
+
* exactly which files and which board facts the upload carries, and then
|
|
7
|
+
* uploads on the click itself — one click, one real order. The URL shown
|
|
8
|
+
* afterwards is the backend's own URL, passed through.
|
|
9
|
+
*/
|
|
10
|
+
import { createElement, useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react'
|
|
11
|
+
import { isAbortError } from './ecad.js'
|
|
12
|
+
import { COPY } from './copy.js'
|
|
13
|
+
import {
|
|
14
|
+
loadOrderConfig, messageOf, placeOrder, prepareFabrication,
|
|
15
|
+
type FabricationProjection, type OrderConfigInfo, type PlacedOrder,
|
|
16
|
+
} from './transport.js'
|
|
17
|
+
import { openOrderPage } from './order-page.js'
|
|
18
|
+
import {
|
|
19
|
+
buttonStyle, C, cardStyle, disabled, dotStyle, MUTED, MONO, MONO_TEXT, pillStyle, R, SECTION_TITLE, SELECT,
|
|
20
|
+
} from './theme.js'
|
|
21
|
+
|
|
22
|
+
export interface OrderPanelProps {
|
|
23
|
+
readonly boardPath: string
|
|
24
|
+
readonly boardTitle: string
|
|
25
|
+
readonly schematicPath?: string
|
|
26
|
+
/** Workspace root of the session showing this panel; the base for relative paths. */
|
|
27
|
+
readonly workspaceRoot?: string
|
|
28
|
+
/** DSH session the panel belongs to, used to scope host-side discovery. */
|
|
29
|
+
readonly session?: string
|
|
30
|
+
readonly configured: boolean
|
|
31
|
+
/**
|
|
32
|
+
* Operation the user already chose (Place Order view).
|
|
33
|
+
*
|
|
34
|
+
* It places that order as soon as the package and the account are ready,
|
|
35
|
+
* because choosing the operation *is* the click there. The card stays visible
|
|
36
|
+
* and its button reads busy while the upload runs.
|
|
37
|
+
*/
|
|
38
|
+
readonly focus?: 'pcb' | 'smt'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const QUANTITIES = [5, 20, 100] as const
|
|
42
|
+
|
|
43
|
+
function formatBytes(bytes: number): string {
|
|
44
|
+
if (bytes < 1024) return `${String(bytes)} B`
|
|
45
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
|
|
46
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function specRows(facts: FabricationProjection['facts']): { label: string; value: string }[] {
|
|
50
|
+
return [
|
|
51
|
+
{ label: COPY.order.layers, value: COPY.order.layersValue(facts.layers) },
|
|
52
|
+
{ label: COPY.order.outline, value: `${facts.widthMm.toFixed(1)} × ${facts.heightMm.toFixed(1)} mm` },
|
|
53
|
+
{ label: COPY.order.thickness, value: `${facts.thicknessMm.toFixed(2)} mm` },
|
|
54
|
+
{ label: COPY.order.minTrace, value: facts.minTrackMm === undefined ? COPY.order.defaultValue : `${facts.minTrackMm.toFixed(2)} mm` },
|
|
55
|
+
{ label: COPY.order.minDrill, value: facts.minViaDrillMm === undefined ? COPY.order.defaultValue : `${facts.minViaDrillMm.toFixed(2)} mm` },
|
|
56
|
+
{ label: COPY.order.outerCopper, value: COPY.order.copperValue(facts.outerOz ?? 1) },
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const SPEC_GRID: CSSProperties = {
|
|
61
|
+
display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(88px, 1fr))', gap: 6,
|
|
62
|
+
}
|
|
63
|
+
const SPEC_CELL: CSSProperties = {
|
|
64
|
+
border: `1px solid ${C.borderSoft}`, borderRadius: R.md, background: C.base,
|
|
65
|
+
padding: '5px 7px', display: 'flex', flexDirection: 'column', gap: 1, minWidth: 0,
|
|
66
|
+
}
|
|
67
|
+
const SPEC_LABEL: CSSProperties = { fontSize: 9.5, color: C.text3, letterSpacing: 0.2 }
|
|
68
|
+
const SPEC_VALUE: CSSProperties = { fontSize: 11, ...MONO_TEXT, color: C.text, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }
|
|
69
|
+
const ROW: CSSProperties = { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap', minWidth: 0 }
|
|
70
|
+
const SPREAD: CSSProperties = { ...ROW, justifyContent: 'space-between' }
|
|
71
|
+
const TAG: CSSProperties = {
|
|
72
|
+
fontSize: 9.5, fontWeight: 600, letterSpacing: 0.6, padding: '1px 5px', borderRadius: R.sm,
|
|
73
|
+
border: '1px solid currentColor', fontFamily: MONO,
|
|
74
|
+
}
|
|
75
|
+
const LINK: CSSProperties = {
|
|
76
|
+
color: C.info, fontSize: 11, fontFamily: MONO, wordBreak: 'break-all', textDecoration: 'underline',
|
|
77
|
+
textUnderlineOffset: 2,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One workflow card: what it will do, what it needs, and its action. */
|
|
81
|
+
function workflowCard(input: {
|
|
82
|
+
readonly tag: string
|
|
83
|
+
readonly tagColor: string
|
|
84
|
+
readonly title: string
|
|
85
|
+
readonly subtitle: string
|
|
86
|
+
readonly details: readonly { label: string; value: string }[]
|
|
87
|
+
readonly action: string
|
|
88
|
+
readonly onAction: () => void
|
|
89
|
+
readonly busy: boolean
|
|
90
|
+
/** Another order is in flight: both cards wait, not just the pressed one. */
|
|
91
|
+
readonly locked?: boolean
|
|
92
|
+
readonly blocked?: string
|
|
93
|
+
}): ReactNode {
|
|
94
|
+
const blocked = input.blocked !== undefined
|
|
95
|
+
const off = blocked || input.busy || input.locked === true
|
|
96
|
+
return createElement(
|
|
97
|
+
'div',
|
|
98
|
+
{ style: cardStyle({ gap: 9 }), 'data-hardware-order-card': input.tag.toLowerCase() },
|
|
99
|
+
createElement(
|
|
100
|
+
'div',
|
|
101
|
+
{ style: { ...ROW, gap: 7 } },
|
|
102
|
+
createElement('span', { style: { ...TAG, color: input.tagColor } }, input.tag),
|
|
103
|
+
createElement('span', { style: { fontSize: 12, fontWeight: 600, color: C.text, minWidth: 0 } }, input.title),
|
|
104
|
+
),
|
|
105
|
+
createElement('p', { style: MUTED }, input.subtitle),
|
|
106
|
+
createElement(
|
|
107
|
+
'div',
|
|
108
|
+
{ style: SPEC_GRID },
|
|
109
|
+
...input.details.map(detail => createElement(
|
|
110
|
+
'div',
|
|
111
|
+
{ key: detail.label, style: SPEC_CELL },
|
|
112
|
+
createElement('span', { style: SPEC_LABEL }, detail.label),
|
|
113
|
+
createElement('span', { style: SPEC_VALUE, title: detail.value }, detail.value),
|
|
114
|
+
)),
|
|
115
|
+
),
|
|
116
|
+
blocked
|
|
117
|
+
? createElement('p', { style: { ...MUTED, color: C.warn } }, input.blocked ?? '')
|
|
118
|
+
: null,
|
|
119
|
+
createElement(
|
|
120
|
+
'button',
|
|
121
|
+
{
|
|
122
|
+
type: 'button', style: { ...buttonStyle('primary'), width: '100%', ...disabled(off) },
|
|
123
|
+
disabled: off,
|
|
124
|
+
'data-hardware-order-action': input.tag.toLowerCase(),
|
|
125
|
+
onClick: input.onAction,
|
|
126
|
+
},
|
|
127
|
+
input.busy ? COPY.order.submitting : input.action,
|
|
128
|
+
),
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
133
|
+
const { boardPath, boardTitle, schematicPath, workspaceRoot, session, configured, focus } = props
|
|
134
|
+
const [config, setConfig] = useState<OrderConfigInfo>()
|
|
135
|
+
const [prepared, setPrepared] = useState<FabricationProjection>()
|
|
136
|
+
const [preparing, setPreparing] = useState(false)
|
|
137
|
+
const [message, setMessage] = useState<string>()
|
|
138
|
+
const [quantity, setQuantity] = useState<number>(20)
|
|
139
|
+
const [placing, setPlacing] = useState<'pcb' | 'smt'>()
|
|
140
|
+
const [placed, setPlaced] = useState<PlacedOrder>()
|
|
141
|
+
const [copied, setCopied] = useState(false)
|
|
142
|
+
const [reopening, setReopening] = useState(false)
|
|
143
|
+
const live = useRef(true)
|
|
144
|
+
/** One in-flight upload at a time, checked before React can re-render. */
|
|
145
|
+
const uploading = useRef(false)
|
|
146
|
+
/** `${boardPath}:${kind}` already auto-placed, so a requote cannot upload twice. */
|
|
147
|
+
const autoPlaced = useRef<string>()
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
live.current = true
|
|
151
|
+
return () => { live.current = false }
|
|
152
|
+
}, [])
|
|
153
|
+
|
|
154
|
+
const submit = async (kind: 'pcb' | 'smt'): Promise<void> => {
|
|
155
|
+
// One upload at a time: a double click must not create two orders, and the
|
|
156
|
+
// guard is a ref so it holds before React re-renders the disabled card.
|
|
157
|
+
if (uploading.current) return
|
|
158
|
+
uploading.current = true
|
|
159
|
+
setPlacing(kind)
|
|
160
|
+
setMessage(undefined)
|
|
161
|
+
try {
|
|
162
|
+
const result = await placeOrder(kind, {
|
|
163
|
+
path: boardPath,
|
|
164
|
+
...(schematicPath === undefined ? {} : { schematic: schematicPath }),
|
|
165
|
+
...(workspaceRoot === undefined ? {} : { cwd: workspaceRoot }),
|
|
166
|
+
...(session === undefined ? {} : { session }),
|
|
167
|
+
quantity,
|
|
168
|
+
}, undefined)
|
|
169
|
+
setPlaced(result)
|
|
170
|
+
// The order exists from here on; show it where the user is working.
|
|
171
|
+
openOrderPage(result.orderUrl)
|
|
172
|
+
} catch (error) {
|
|
173
|
+
setMessage(messageOf(error))
|
|
174
|
+
} finally {
|
|
175
|
+
uploading.current = false
|
|
176
|
+
setPlacing(undefined)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// A user who picked PCBA in the Place Order view has already made the choice:
|
|
181
|
+
// the order is placed as soon as the package and the account are ready, with
|
|
182
|
+
// the same single upload path the card uses. The key keeps a second render
|
|
183
|
+
// (or a requote) from uploading twice for one visit.
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (focus === undefined || prepared === undefined || !live.current) return
|
|
186
|
+
if (config?.hasToken !== true || placing !== undefined) return
|
|
187
|
+
const key = `${boardPath}:${focus}`
|
|
188
|
+
if (autoPlaced.current === key) return
|
|
189
|
+
autoPlaced.current = key
|
|
190
|
+
void submit(focus)
|
|
191
|
+
}, [focus, prepared, config, boardPath, placing])
|
|
192
|
+
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
loadOrderConfig()
|
|
195
|
+
.then((value) => { if (live.current) setConfig(value) })
|
|
196
|
+
.catch((error: unknown) => { if (live.current) setMessage(messageOf(error)) })
|
|
197
|
+
}, [])
|
|
198
|
+
|
|
199
|
+
// Preparing the package is local: gerbers, drill files and CSVs come from the
|
|
200
|
+
// saved board. Nothing leaves the machine until the user clicks an order card.
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
if (!configured) {
|
|
203
|
+
setPrepared(undefined)
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
const controller = new AbortController()
|
|
207
|
+
setPreparing(true)
|
|
208
|
+
setMessage(undefined)
|
|
209
|
+
setPlaced(undefined)
|
|
210
|
+
prepareFabrication(boardPath, schematicPath, workspaceRoot, controller.signal, session)
|
|
211
|
+
.then((value) => { if (!controller.signal.aborted) setPrepared(value) })
|
|
212
|
+
.catch((error: unknown) => {
|
|
213
|
+
if (controller.signal.aborted || isAbortError(error)) return
|
|
214
|
+
setMessage(messageOf(error))
|
|
215
|
+
})
|
|
216
|
+
.finally(() => { if (!controller.signal.aborted) setPreparing(false) })
|
|
217
|
+
return () => { controller.abort() }
|
|
218
|
+
}, [boardPath, schematicPath, workspaceRoot, session, configured])
|
|
219
|
+
|
|
220
|
+
const facts = prepared?.facts
|
|
221
|
+
const specs = useMemo(() => (facts === undefined ? [] : specRows(facts)), [facts])
|
|
222
|
+
|
|
223
|
+
const copy = async (): Promise<void> => {
|
|
224
|
+
if (placed === undefined) return
|
|
225
|
+
try {
|
|
226
|
+
await navigator.clipboard.writeText(placed.orderUrl)
|
|
227
|
+
setCopied(true)
|
|
228
|
+
setTimeout(() => { setCopied(false) }, 1600)
|
|
229
|
+
} catch {
|
|
230
|
+
setCopied(false)
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const reopen = async (): Promise<void> => {
|
|
235
|
+
if (placed === undefined) return
|
|
236
|
+
setReopening(true)
|
|
237
|
+
setMessage(undefined)
|
|
238
|
+
try {
|
|
239
|
+
openOrderPage(placed.orderUrl)
|
|
240
|
+
setPlaced({ ...placed, launched: true, status: 'launched' })
|
|
241
|
+
} catch (error) {
|
|
242
|
+
setMessage(messageOf(error))
|
|
243
|
+
} finally {
|
|
244
|
+
setReopening(false)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const zipSize = prepared === undefined ? undefined : formatBytes(prepared.archive.zipBytes)
|
|
249
|
+
const assembly = prepared?.assembly
|
|
250
|
+
const tokenReady = config?.hasToken ?? false
|
|
251
|
+
|
|
252
|
+
const header = createElement(
|
|
253
|
+
'div',
|
|
254
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
255
|
+
createElement(
|
|
256
|
+
'div',
|
|
257
|
+
{ style: SPREAD },
|
|
258
|
+
createElement(
|
|
259
|
+
'h3',
|
|
260
|
+
{ style: { margin: 0, fontSize: 13, fontWeight: 600, color: C.text, display: 'flex', alignItems: 'center', gap: 6 } },
|
|
261
|
+
createElement('span', { style: dotStyle(C.accent) }),
|
|
262
|
+
COPY.order.title,
|
|
263
|
+
),
|
|
264
|
+
preparing
|
|
265
|
+
? createElement('span', { style: pillStyle('info') }, COPY.order.packaging)
|
|
266
|
+
: prepared !== undefined
|
|
267
|
+
? createElement('span', { style: pillStyle('ok') }, COPY.order.packageReady)
|
|
268
|
+
: createElement('span', { style: pillStyle(configured ? 'muted' : 'warn') }, configured ? COPY.order.packagePending : COPY.viewer.kicadMissing),
|
|
269
|
+
),
|
|
270
|
+
createElement('p', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10.5 } }, boardTitle),
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
const packageCard = createElement(
|
|
274
|
+
'div',
|
|
275
|
+
{ style: cardStyle() },
|
|
276
|
+
createElement('div', { style: SPREAD },
|
|
277
|
+
createElement('span', { style: SECTION_TITLE }, COPY.order.packageCard),
|
|
278
|
+
prepared === undefined
|
|
279
|
+
? null
|
|
280
|
+
: createElement('span', { style: pillStyle('muted') }, COPY.order.packageFiles(prepared.archive.files.length, zipSize ?? '')),
|
|
281
|
+
),
|
|
282
|
+
prepared === undefined
|
|
283
|
+
? createElement('p', { style: MUTED },
|
|
284
|
+
preparing ? COPY.order.packageRunning : COPY.order.packageNotPrepared)
|
|
285
|
+
: createElement(
|
|
286
|
+
'div',
|
|
287
|
+
{
|
|
288
|
+
style: {
|
|
289
|
+
display: 'flex', flexWrap: 'wrap', gap: 4, maxHeight: 74, overflow: 'auto',
|
|
290
|
+
border: `1px solid ${C.borderSoft}`, borderRadius: R.md, padding: 6, background: C.base,
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
...prepared.archive.files.map(file => createElement(
|
|
294
|
+
'span',
|
|
295
|
+
{ key: file.name, style: { ...pillStyle('muted'), fontSize: 9.5, padding: '0 5px' }, title: `${file.name} · ${formatBytes(file.bytes)}` },
|
|
296
|
+
file.name,
|
|
297
|
+
)),
|
|
298
|
+
),
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
const pcbCard = workflowCard({
|
|
302
|
+
tag: 'PCB',
|
|
303
|
+
tagColor: C.ok,
|
|
304
|
+
title: COPY.order.pcbTitle,
|
|
305
|
+
subtitle: prepared === undefined
|
|
306
|
+
? COPY.order.pcbSubtitle
|
|
307
|
+
: COPY.order.pcbSummary(prepared.archive.zipName, prepared.archive.files.length, zipSize ?? ''),
|
|
308
|
+
details: specs.length === 0
|
|
309
|
+
? [{ label: COPY.order.boardFile, value: boardTitle }]
|
|
310
|
+
: specs,
|
|
311
|
+
action: COPY.order.pcbAction,
|
|
312
|
+
onAction: () => { void submit('pcb') },
|
|
313
|
+
busy: placing === 'pcb',
|
|
314
|
+
locked: placing !== undefined && placing !== 'pcb',
|
|
315
|
+
...(configured && prepared !== undefined
|
|
316
|
+
? tokenReady ? {} : { blocked: COPY.order.signInToOrder }
|
|
317
|
+
: { blocked: configured ? COPY.order.waitingForPackage : COPY.order.configureToPackage }),
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
const smtCard = workflowCard({
|
|
321
|
+
tag: 'PCBA',
|
|
322
|
+
tagColor: C.info,
|
|
323
|
+
title: COPY.order.smtTitle,
|
|
324
|
+
subtitle: assembly === undefined
|
|
325
|
+
? COPY.order.smtSubtitle
|
|
326
|
+
: COPY.order.smtSummary(assembly.positions, assembly.bomLines, formatBytes(assembly.bomBytes + assembly.positionsBytes)),
|
|
327
|
+
details: [
|
|
328
|
+
{ label: COPY.order.placements, value: assembly === undefined ? '—' : String(assembly.positions) },
|
|
329
|
+
{ label: COPY.order.bomLines, value: assembly === undefined ? '—' : String(assembly.bomLines) },
|
|
330
|
+
{ label: COPY.order.credential, value: tokenReady ? COPY.order.signedIn : COPY.order.signedOut },
|
|
331
|
+
],
|
|
332
|
+
action: COPY.order.smtAction,
|
|
333
|
+
onAction: () => { void submit('smt') },
|
|
334
|
+
busy: placing === 'smt',
|
|
335
|
+
locked: placing !== undefined && placing !== 'smt',
|
|
336
|
+
...(assembly === undefined
|
|
337
|
+
? { blocked: COPY.order.selectRootSchematic }
|
|
338
|
+
: tokenReady
|
|
339
|
+
? {}
|
|
340
|
+
: { blocked: COPY.order.signInToOrderSmt }),
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
const agentHint = createElement(
|
|
344
|
+
'div',
|
|
345
|
+
{ style: { ...ROW, gap: 4, paddingTop: 2 } },
|
|
346
|
+
createElement('span', { style: { fontSize: 10, color: C.text3 } }, COPY.order.agentEntryPoints),
|
|
347
|
+
...['quote_pcb', 'place_pcb_order', 'quote_smt', 'place_smt_order'].map(name => createElement(
|
|
348
|
+
'span', { key: name, style: { ...pillStyle('muted'), fontSize: 9.5 } }, name,
|
|
349
|
+
)),
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
const resultCard = placed === undefined ? null : createElement(
|
|
353
|
+
'div',
|
|
354
|
+
{ style: cardStyle({ borderColor: 'rgba(52,211,153,0.4)' }), 'data-hardware-order-result': placed.kind },
|
|
355
|
+
createElement('div', { style: SPREAD },
|
|
356
|
+
createElement('span', { style: SECTION_TITLE },
|
|
357
|
+
placed.kind === 'pcb' ? COPY.order.resultTitlePcb : COPY.order.resultTitleSmt),
|
|
358
|
+
createElement('span', { style: pillStyle(placed.launched ? 'ok' : 'muted') },
|
|
359
|
+
placed.launched ? COPY.order.resultLaunched : COPY.order.resultReady),
|
|
360
|
+
),
|
|
361
|
+
// The host sends its own English sentence in `placed.message`; the visible
|
|
362
|
+
// copy is derived here so the panel speaks one language. The host string is
|
|
363
|
+
// kept on the object for tooling, not rendered.
|
|
364
|
+
createElement('p', { style: MUTED },
|
|
365
|
+
placed.launched
|
|
366
|
+
? COPY.order.resultLaunchedMessage(placed.kind === 'pcb' ? 'PCB' : COPY.order.smtShort)
|
|
367
|
+
: COPY.order.resultReadyMessage(placed.kind === 'pcb' ? 'PCB' : COPY.order.smtShort)),
|
|
368
|
+
createElement('a', {
|
|
369
|
+
style: LINK, href: placed.orderUrl, target: '_blank', rel: 'noreferrer noopener',
|
|
370
|
+
'data-hardware-order-url': true,
|
|
371
|
+
}, placed.orderUrl),
|
|
372
|
+
createElement('p', { style: { ...MUTED, fontSize: 10 } }, COPY.order.resultNote),
|
|
373
|
+
createElement('div', { style: ROW },
|
|
374
|
+
createElement('button', {
|
|
375
|
+
type: 'button',
|
|
376
|
+
style: { ...buttonStyle('primary'), ...disabled(reopening) },
|
|
377
|
+
disabled: reopening,
|
|
378
|
+
'data-hardware-order-reopen': true,
|
|
379
|
+
onClick: () => { void reopen() },
|
|
380
|
+
}, reopening ? COPY.order.opening : COPY.order.openInBrowser),
|
|
381
|
+
createElement('button', { type: 'button', style: buttonStyle('secondary'), onClick: () => { void copy() } },
|
|
382
|
+
copied ? COPY.order.copied : COPY.order.copyUrl),
|
|
383
|
+
createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } },
|
|
384
|
+
`${placed.archive.zipName} · ${formatBytes(placed.archive.zipBytes)}`),
|
|
385
|
+
),
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
return createElement(
|
|
390
|
+
'div',
|
|
391
|
+
{ style: { position: 'relative', display: 'flex', flexDirection: 'column', gap: 10, minHeight: 0 }, 'data-hardware-order': true },
|
|
392
|
+
header,
|
|
393
|
+
...(message === undefined ? [] : [createElement('p', {
|
|
394
|
+
key: 'message', role: 'status', style: { ...MUTED, color: C.warn, borderLeft: `2px solid ${C.warn}`, paddingLeft: 8 },
|
|
395
|
+
}, message)]),
|
|
396
|
+
createElement(
|
|
397
|
+
'div',
|
|
398
|
+
{ style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(250px, 1fr))', gap: 10 } },
|
|
399
|
+
pcbCard,
|
|
400
|
+
smtCard,
|
|
401
|
+
),
|
|
402
|
+
createElement(
|
|
403
|
+
'div',
|
|
404
|
+
{ style: { ...SPREAD, ...cardStyle({ flexDirection: 'row', alignItems: 'center' }) } },
|
|
405
|
+
createElement('span', { style: { fontSize: 11, color: C.text2 } }, COPY.order.batch),
|
|
406
|
+
createElement(
|
|
407
|
+
'select',
|
|
408
|
+
{
|
|
409
|
+
style: { ...SELECT, width: 'auto' }, value: quantity,
|
|
410
|
+
'data-hardware-order-quantity': true,
|
|
411
|
+
onChange: (event: { currentTarget: HTMLSelectElement }) => { setQuantity(Number(event.currentTarget.value)) },
|
|
412
|
+
},
|
|
413
|
+
...QUANTITIES.map(count => createElement('option', { key: count, value: count }, COPY.order.batchUnits(count))),
|
|
414
|
+
),
|
|
415
|
+
createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } }, COPY.order.quoteBasis(quantity)),
|
|
416
|
+
),
|
|
417
|
+
packageCard,
|
|
418
|
+
resultCard,
|
|
419
|
+
// One click uploads: say so where the click happens, not in a dialog after it.
|
|
420
|
+
createElement('p', { style: { ...MUTED, fontSize: 10 }, 'data-hardware-order-hint': true }, COPY.order.uploadHint),
|
|
421
|
+
agentHint,
|
|
422
|
+
)
|
|
423
|
+
}
|