Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a maintenance mode toggle. #5

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' });
}
};