generated from StanfordBDHG/NextJSTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Add "Admin" view ## ♻️ Current situation & Problem Admins need to be able to update static data and seed data. ## ⚙️ Release Notes * Add "Admin" view * Update models package ![image](https://github.com/user-attachments/assets/6324d04d-bc49-4e55-9be4-cc22f1587a52) ### Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
1 parent
5f72377
commit 20f48af
Showing
7 changed files
with
126 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// This source file is part of the Stanford Biodesign Digital Health ENGAGE-HF open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2025 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import { UserType } from '@stanfordbdhg/engagehf-models' | ||
import { Button } from '@stanfordspezi/spezi-web-design-system/components/Button' | ||
import { toast } from '@stanfordspezi/spezi-web-design-system/components/Toaster' | ||
import { PageTitle } from '@stanfordspezi/spezi-web-design-system/molecules/DashboardLayout' | ||
import { useMutation } from '@tanstack/react-query' | ||
import { createFileRoute } from '@tanstack/react-router' | ||
import { MonitorCog } from 'lucide-react' | ||
import { Helmet } from 'react-helmet' | ||
import { callables, ensureType } from '@/modules/firebase/app' | ||
import { DashboardLayout } from '../DashboardLayout' | ||
|
||
const AdminPage = () => { | ||
const updateStaticData = useMutation({ | ||
mutationFn: () => callables.updateStaticData({}), | ||
onSuccess: () => toast.success('Successfully updated static data'), | ||
onError: () => toast.error('Updating static data failed. Please try again'), | ||
}) | ||
|
||
const seedData = useMutation({ | ||
mutationFn: () => callables.defaultSeed({}), | ||
onSuccess: () => toast.success('Successfully seeded data'), | ||
onError: () => toast.error('Seeding data failed. Please try again'), | ||
}) | ||
|
||
return ( | ||
<DashboardLayout title={<PageTitle title="Admin" icon={<MonitorCog />} />}> | ||
<Helmet> | ||
<title>Admin</title> | ||
</Helmet> | ||
<div className="flex flex-col items-start gap-8"> | ||
<section className="flex flex-col items-start gap-2"> | ||
<Button | ||
onClick={() => updateStaticData.mutate()} | ||
isPending={updateStaticData.isPending} | ||
> | ||
Update static data | ||
</Button> | ||
<p className="text-sm font-light"> | ||
Updates static data, like medications, organizations and video | ||
sections | ||
</p> | ||
</section> | ||
<section className="flex flex-col items-start gap-2"> | ||
<Button | ||
onClick={() => seedData.mutate()} | ||
isPending={seedData.isPending} | ||
> | ||
Seed data | ||
</Button> | ||
<p className="text-sm font-light"> | ||
Seeds the application with test users | ||
</p> | ||
</section> | ||
</div> | ||
</DashboardLayout> | ||
) | ||
} | ||
|
||
export const Route = createFileRoute('/_dashboard/admin/')({ | ||
component: AdminPage, | ||
beforeLoad: () => ensureType([UserType.admin]), | ||
}) |