Complete customer transfers on first authenticated inventory
Rust development slice / linux (push) Failing after 8s
Rust development slice / linux (push) Failing after 8s
This commit is contained in:
@@ -5,11 +5,10 @@ import { allowed } from './safety';
|
||||
|
||||
type Transfer = {
|
||||
id: string;
|
||||
state: 'pending' | 'enrolled' | 'ready' | 'completed';
|
||||
state: 'pending' | 'enrolled' | 'completed';
|
||||
tenant: string;
|
||||
asset: string | null;
|
||||
agent: string | null;
|
||||
hostname: string | null;
|
||||
};
|
||||
|
||||
function parseTransfer(value: unknown): Transfer | null {
|
||||
@@ -17,14 +16,13 @@ function parseTransfer(value: unknown): Transfer | null {
|
||||
const t = record(value);
|
||||
const { transfer_id: id, target_tenant_id: tenant, state } = t;
|
||||
if (typeof id !== 'string' || typeof tenant !== 'string' ||
|
||||
(state !== 'pending' && state !== 'enrolled' && state !== 'ready' && state !== 'completed')) {
|
||||
(state !== 'pending' && state !== 'enrolled' && state !== 'completed')) {
|
||||
throw new Error('Der Server lieferte keinen gültigen Kundenwechsel.');
|
||||
}
|
||||
return {
|
||||
id, tenant, state,
|
||||
asset: typeof t.target_asset_id === 'string' ? t.target_asset_id : null,
|
||||
agent: typeof t.target_agent_id === 'string' ? t.target_agent_id : null,
|
||||
hostname: typeof t.target_hostname === 'string' ? t.target_hostname : null
|
||||
agent: typeof t.target_agent_id === 'string' ? t.target_agent_id : null
|
||||
};
|
||||
}
|
||||
|
||||
@@ -35,7 +33,6 @@ function transferError(error: unknown) {
|
||||
TRANSFER_ALREADY_PENDING: 'Für dieses Gerät ist bereits ein Kundenwechsel vorgemerkt.',
|
||||
TRANSFER_ALREADY_STARTED: 'Der Agent übernimmt bereits die neue Kopplung.',
|
||||
TRANSFER_AGENT_UPDATE_REQUIRED: 'Dieses Gerät benötigt eine Agentversion mit Kundenwechsel.',
|
||||
TRANSFER_TARGET_NOT_READY: 'Warten Sie auf die erste Inventarmeldung beim Zielkunden.',
|
||||
TRANSFER_SOURCE_INACTIVE: 'Diese Kopplung ist im bisherigen Kunden nicht mehr aktiv.',
|
||||
FORBIDDEN: 'Für den Kundenwechsel fehlen Rechte beim bisherigen Kunden oder beim Zielkunden.',
|
||||
NOT_FOUND: 'Das Gerät oder der Zielkunde ist für diese Sitzung nicht verfügbar.'
|
||||
@@ -56,7 +53,6 @@ export function DeviceCustomerTransfer({ auth, customer, asset, agent, customers
|
||||
}) {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const [target, setTarget] = useState('');
|
||||
const [confirmed, setConfirmed] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const base = tenantPath(customer, '/devices/' + encodeURIComponent(asset) + '/customer-transfer');
|
||||
@@ -80,7 +76,6 @@ export function DeviceCustomerTransfer({ auth, customer, asset, agent, customers
|
||||
setError(null);
|
||||
try {
|
||||
await request(base + suffix + query, { csrf: auth.csrf_token, tenantId: customer, body });
|
||||
setConfirmed(false);
|
||||
status.reload();
|
||||
} catch (e) {
|
||||
setError(transferError(e));
|
||||
@@ -99,17 +94,9 @@ export function DeviceCustomerTransfer({ auth, customer, asset, agent, customers
|
||||
<button disabled={busy} className="quiet"
|
||||
onClick={() => void submit('/' + encodeURIComponent(current.id) + '/cancel', {})}>Vormerkung abbrechen</button>
|
||||
</>}
|
||||
{current.state === 'enrolled' && <p role="status">Die neue Kopplung wartet auf ihre erste Inventarmeldung.</p>}
|
||||
{current.state === 'ready' && <>
|
||||
<p role="status"><strong>{current.hostname}</strong> hat sich beim Zielkunden gemeldet.</p>
|
||||
<label className="check"><input type="checkbox" checked={confirmed} onChange={e => setConfirmed(e.target.checked)} />
|
||||
Ich bestätige den Kundenwechsel für dieses Gerät.
|
||||
</label>
|
||||
<button className="primary" disabled={busy || !confirmed}
|
||||
onClick={() => void submit('/' + encodeURIComponent(current.id) + '/complete', {})}>Kundenwechsel abschließen</button>
|
||||
</>}
|
||||
{current.state === 'enrolled' && <p role="status">Der Wechsel wird mit der ersten Inventarmeldung beim Zielkunden abgeschlossen.</p>}
|
||||
{current.state === 'completed' && <p role="status">Kundenwechsel abgeschlossen. Die frühere Kopplung steht in der Historie.</p>}
|
||||
{current.asset && current.agent && ['ready', 'completed'].includes(current.state) &&
|
||||
{current.asset && current.agent && current.state === 'completed' &&
|
||||
<a href={'#geraete/' + [current.tenant, current.asset, current.agent].map(encodeURIComponent).join('/')}>
|
||||
Neue Kopplung öffnen
|
||||
</a>}
|
||||
@@ -126,7 +113,7 @@ export function DeviceCustomerTransfer({ auth, customer, asset, agent, customers
|
||||
</select></label>
|
||||
{target && (destination.error || destination.data && !canEnroll) &&
|
||||
<p>Für diesen Zielkunden fehlt das Recht zur Geräteaufnahme oder zum Lesen des Inventars.</p>}
|
||||
<button className="primary" disabled={busy || !canEnroll}>Kundenwechsel vormerken</button>
|
||||
<button className="primary" disabled={busy || !canEnroll}>Kundenwechsel starten</button>
|
||||
</form>
|
||||
</> : <p>Für diese Sitzung ist kein weiterer Kunde verfügbar.</p>
|
||||
: <p>Der Agent benötigt ein Update für den Kundenwechsel.</p>
|
||||
|
||||
Reference in New Issue
Block a user