Skip to content

Commit

Permalink
Merge pull request #5 from temporalio/rh-maintenance-mode
Browse files Browse the repository at this point in the history
Add a maintenance mode toggle.
  • Loading branch information
tomwheeler authored Jul 5, 2024
2 parents 782e1ce + ba46448 commit 99e186f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/lib/components/shipment-status.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
});
}
const inactiveStatuses = ['pending', 'unavailable', 'cancelled'];
const inactiveStatuses = ['pending', 'unavailable', 'cancelled', 'failed'];
const activeStatuses = ['booked', 'dispatched', 'delivered'];
$: finalStatus = status || 'pending';
Expand All @@ -24,6 +24,7 @@
class:active={!inactive && currentIndex === index}
class:completed={!inactive && currentIndex > index}
class:incomplete={!inactive && currentIndex < index}
class:failed={s === 'failed'}
class:pending={s === 'pending'}
class:unavailable={s === 'unavailable'}
class:cancelled={s === 'cancelled'}
Expand Down Expand Up @@ -87,7 +88,8 @@
li.incomplete::before,
li.unavailable::before,
li.cancelled::before {
li.cancelled::before,
li.failed::before {
background: lightcoral;
}
Expand Down
6 changes: 3 additions & 3 deletions src/routes/admin/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { env } from '$env/dynamic/private';

export const load = async () => {
const response = await fetch(`${env.FRAUD_API_URL}/limit`);
const { limit } = await response.json();
return { limit };
const response = await fetch(`${env.FRAUD_API_URL}/settings`);
const { limit, maintenanceMode } = await response.json();
return { limit, maintenanceMode };
};
15 changes: 12 additions & 3 deletions src/routes/admin/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export let data;
$: ({ limit } = data);
$: ({ limit, maintenanceMode } = data);
$: newLimit = limit || 0;
Expand All @@ -16,18 +16,27 @@
await fetch('/api/limit', { method: 'POST', body: JSON.stringify({ limit: newLimit }) });
await invalidateAll();
};
const onMaintenanceMode = async () => {
await fetch('/api/maintenance', { method: 'POST' });
await invalidateAll();
};
</script>

<div class="flex items-center justify-start">
<h1>Fraud Check</h1>
<h1>Admin</h1>
<p>
Limit: <strong
Fraud Limit: <strong
>{limit
? (limit / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' })
: 'Unlimited'}</strong
>
</p>
<p>
Maintenance Mode: <strong>{maintenanceMode ? 'Enabled' : 'Disabled'}</strong>
</p>
<input type="number" bind:value={newLimit} />
<button on:click={onLimit}>Set Limit</button>
<button on:click={onMaintenanceMode}>Maintenance Mode</button>
<button on:click={onReset}>Reset</button>
</div>
13 changes: 13 additions & 0 deletions src/routes/api/maintenance/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { env } from '$env/dynamic/private';

export const POST: RequestHandler = async () => {
try {
const response = await fetch(`${env.FRAUD_API_URL}/maintenance`, {
method: 'POST',
});
return json({ status: 'ok', body: response });
} catch (e) {
return json({ status: 'error' });
}
};

0 comments on commit 99e186f

Please sign in to comment.