From 5a86767598ee0e9928424fedde88b0827bf50494 Mon Sep 17 00:00:00 2001 From: Johnny Gear Date: Sat, 7 Mar 2026 14:49:09 -0600 Subject: [PATCH] Orders - Show warning if user doesn't have a mastodon account set --- web/api.py | 10 ++++++++++ web/vite/src/OrderSets.tsx | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/web/api.py b/web/api.py index a5839f8..edb26ea 100644 --- a/web/api.py +++ b/web/api.py @@ -115,6 +115,16 @@ def authorized_sub(func): return func(*args, **kwargs) return wrapper +@api.route('/subs/') +@login_required +@authorized_sub +def sub(username, sub): + return jsonify({ + "username": sub.telegram_username, + "mastodon_server": sub.mastodon_server.name if sub.mastodon_server is not None else None, + "mastodon_username": sub.mastodon_username + }) + @api.route('/orders/') @login_required def my_order_sets(): diff --git a/web/vite/src/OrderSets.tsx b/web/vite/src/OrderSets.tsx index 9a093d7..83e8970 100644 --- a/web/vite/src/OrderSets.tsx +++ b/web/vite/src/OrderSets.tsx @@ -7,13 +7,16 @@ import { Badge, Box, RingProgress, + Alert, } from "@mantine/core"; +import { IconAlertTriangle } from "@tabler/icons-react"; import { TimeValue } from "@mantine/dates"; import { IconPencil, IconPlus, IconTrash } from "@tabler/icons-react"; import { ConfirmDialogButton } from "./ConfirmDialogButton"; import { NavigateButton } from "./NavigateButton"; -import { useFetcher } from "react-router"; +import { Link, useFetcher } from "react-router"; +import { useUserContext } from "./UserContext"; export interface OrderSetProps { orderSets: (Pick< @@ -39,6 +42,7 @@ export const OrderSets: React.FC = ({ username, linkBack, }) => { + const { username: current_user } = useUserContext(); const fetcher = useFetcher(); const handleDelete = React.useCallback( (id: number) => { @@ -50,12 +54,44 @@ export const OrderSets: React.FC = ({ [fetcher], ); + const [isMastodonSet, setIsMastodonSet] = React.useState(true); + React.useEffect(() => { + fetch(`/api/subs/${username}`) + .then((response) => response.json()) + .then((data) => { + if (!data.mastodon_server || !data.mastodon_username) { + setIsMastodonSet(false); + } + }); + }, [username]); + return ( <> Order Sets for {username} {linkBack ? linkBack : null} + {orderSets.length > 0 && isMastodonSet ? null : ( + + } + my="md" + w="40rem" + > + {username} must authorize with a Mastodon account before + orders can be issued. + {username === current_user ? ( + <> +
+ Edit Profile + + ) : null} +
+
+ )} {orderSets ? orderSets.map(