Add load example button, remove defaultConfig passed in api/cron route

This commit is contained in:
Xevion
2023-02-27 19:27:05 -06:00
parent 081e23c019
commit 8585be0849
2 changed files with 38 additions and 27 deletions

View File

@@ -40,32 +40,7 @@ export default async function handler(
async function innerFunction(): Promise<ResponseStatus> {
const now = new Date();
const config = await fetchConfiguration({
times: [
{
time: '03:13',
maxLate: '00:10',
message: 'The bus is leaving soon.',
days: [
'monday',
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday',
'sunday'
],
name: 'B'
},
{
name: 'A',
message: 'The bus is leaving soon.',
time: '23:26',
maxLate: '00:10',
days: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
}
]
});
const config = await fetchConfiguration();
const matching = await getMatchingTime(config, now);
// No matching time - no notification to send.

View File

@@ -43,6 +43,33 @@ export async function getServerSideProps({
};
}
const exampleConfiguration = {
times: [
{
time: '03:13',
maxLate: '00:10',
message: 'The bus is leaving soon.',
days: [
'monday',
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday',
'sunday'
],
name: 'B'
},
{
name: 'A',
message: 'The bus is leaving soon.',
time: '23:26',
maxLate: '00:10',
days: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
}
]
};
const IndexPage: NextPage<Props> = ({ config }) => {
const [code, setCode] = useState(config);
const router = useRouter();
@@ -103,7 +130,16 @@ const IndexPage: NextPage<Props> = ({ config }) => {
</div>
<div className="flex justify-between pt-2">
<div className="flex-shrink-0">{validationElement}</div>
<div className="flex-shrink-0">
<div className="flex-shrink-0 space-x-4">
<button
onClick={(e) => {
e.preventDefault();
setCode(JSON.stringify(exampleConfiguration, null, 4));
}}
className="inline-flex items-center rounded-md border border-transparent bg-zinc-700 hover:bg-zinc-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
>
Load Example
</button>
<button
type="submit"
className="inline-flex items-center rounded-md border border-transparent bg-indigo-700 hover:bg-indigo-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"