Compare commits
5 Commits
2b42033c70
...
e489b045fc
| Author | SHA1 | Date | |
|---|---|---|---|
| e489b045fc | |||
| b00cde2a6e | |||
| bfa04936b2 | |||
| 24fd13340e | |||
| d037f1ded0 |
@@ -130,7 +130,7 @@ def row_to_my_order(row: sqlite3.Row) -> dict:
|
||||
except json.JSONDecodeError:
|
||||
submission_choices = {}
|
||||
|
||||
return {
|
||||
result = {
|
||||
"id": row["id"],
|
||||
"title": row["title"],
|
||||
"description": row["description"],
|
||||
@@ -145,3 +145,8 @@ def row_to_my_order(row: sqlite3.Row) -> dict:
|
||||
"paid": bool(row["paid"]) if row["paid"] is not None else False,
|
||||
},
|
||||
}
|
||||
|
||||
if "has_unpaid_submissions" in row.keys() and row["has_unpaid_submissions"] is not None:
|
||||
result["has_unpaid_submissions"] = bool(row["has_unpaid_submissions"])
|
||||
|
||||
return result
|
||||
|
||||
@@ -674,7 +674,12 @@ def get_my_orders(
|
||||
uot.submission_token,
|
||||
s.choices_json,
|
||||
s.accepted,
|
||||
s.paid
|
||||
s.paid,
|
||||
CASE
|
||||
WHEN uot.admin_token IS NOT NULL THEN
|
||||
(SELECT COUNT(*) FROM submissions s2 WHERE s2.group_order_id = go.id AND s2.accepted = 1 AND (s2.paid IS NULL OR s2.paid = 0))
|
||||
ELSE 0
|
||||
END AS has_unpaid_submissions
|
||||
FROM user_order_tokens uot
|
||||
JOIN group_orders go ON go.id = uot.group_order_id
|
||||
LEFT JOIN submissions s ON s.submission_token = uot.submission_token
|
||||
|
||||
+7
-2
@@ -36,15 +36,20 @@ services:
|
||||
container_name: lunchtime-mailpit
|
||||
ports:
|
||||
- "8025:8025"
|
||||
volumes:
|
||||
- mailpit-data:/data
|
||||
restart: unless-stopped
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "8020:8080"
|
||||
volumes:
|
||||
- ../nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
depends_on:
|
||||
- backend
|
||||
- frontend
|
||||
restart: unless-stopped
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
mailpit-data:
|
||||
@@ -6,6 +6,7 @@ import ExportSelectionModal, { type ExportSelectionState } from "../modals/Expor
|
||||
|
||||
type MenuConfigImportExportProps = {
|
||||
config?: OrderFormConfig | null;
|
||||
description?: string;
|
||||
onImportConfig?: (config: OrderFormConfig) => void | Promise<void>;
|
||||
showImport?: boolean;
|
||||
showExport?: boolean;
|
||||
@@ -23,6 +24,7 @@ function normalizeConfig(value: unknown): OrderFormConfig {
|
||||
|
||||
export default function MenuConfigImportExport({
|
||||
config,
|
||||
description,
|
||||
onImportConfig,
|
||||
showImport = true,
|
||||
showExport = true,
|
||||
@@ -98,8 +100,8 @@ export default function MenuConfigImportExport({
|
||||
payload.title = fileNameBase || "";
|
||||
}
|
||||
|
||||
if (exportSelection.description) {
|
||||
payload.description = "";
|
||||
if (exportSelection.description || description) {
|
||||
payload.description = description || "";
|
||||
}
|
||||
|
||||
if (exportSelection.menu) {
|
||||
|
||||
@@ -76,6 +76,7 @@ export default function ReadOnlyOrderOverviewCard({
|
||||
extra={
|
||||
<MenuConfigImportExport
|
||||
config={currentConfig}
|
||||
description={currentDescription}
|
||||
showImport={false}
|
||||
onImportConfig={onImportConfig}
|
||||
fileNameBase={order.title || "order"}
|
||||
|
||||
@@ -51,17 +51,13 @@ export default function AdminSubmissionsCard({
|
||||
onOpenMailto,
|
||||
selectedRowKeys,
|
||||
onSelectedRowKeysChange,
|
||||
pagedSubmissions,
|
||||
submissions,
|
||||
deletingId,
|
||||
savingStatusKey,
|
||||
onDeleteSubmission,
|
||||
onUpdateSubmissionStatus,
|
||||
totalEstimatedText,
|
||||
selectedCount,
|
||||
submissionsPage,
|
||||
pageSize,
|
||||
totalCount,
|
||||
onSubmissionsPageChange,
|
||||
}: {
|
||||
searchQuery: string;
|
||||
selectedSubmissionState: "all" | "pending" | "unpaid" | "paid";
|
||||
@@ -74,17 +70,13 @@ export default function AdminSubmissionsCard({
|
||||
onOpenMailto: () => void;
|
||||
selectedRowKeys: Array<string | number>;
|
||||
onSelectedRowKeysChange: (keys: Array<string | number>) => void;
|
||||
pagedSubmissions: any[];
|
||||
submissions: any[];
|
||||
deletingId: string | number | null;
|
||||
savingStatusKey: string | null;
|
||||
onDeleteSubmission: (id: string | number) => void;
|
||||
onUpdateSubmissionStatus: (submission: any, changes: { accepted?: boolean; paid?: boolean }) => void;
|
||||
totalEstimatedText: string | null;
|
||||
selectedCount: number;
|
||||
submissionsPage: number;
|
||||
pageSize: number;
|
||||
totalCount: number;
|
||||
onSubmissionsPageChange: (page: number) => void;
|
||||
}) {
|
||||
const columns = [
|
||||
{
|
||||
@@ -224,14 +216,14 @@ export default function AdminSubmissionsCard({
|
||||
<Table
|
||||
rowKey="id"
|
||||
columns={columns}
|
||||
dataSource={pagedSubmissions}
|
||||
dataSource={submissions}
|
||||
rowSelection={{
|
||||
selectedRowKeys,
|
||||
onChange: (nextSelectedRowKeys) =>
|
||||
onSelectedRowKeysChange(nextSelectedRowKeys as Array<string | number>),
|
||||
}}
|
||||
pagination={false}
|
||||
scroll={{ x: true }}
|
||||
scroll={{ y: 400, x: true }}
|
||||
/>
|
||||
<Flex
|
||||
justify="space-between"
|
||||
@@ -249,14 +241,6 @@ export default function AdminSubmissionsCard({
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
<Pagination
|
||||
current={submissionsPage}
|
||||
pageSize={pageSize}
|
||||
total={totalCount}
|
||||
showSizeChanger={false}
|
||||
hideOnSinglePage
|
||||
onChange={onSubmissionsPageChange}
|
||||
/>
|
||||
</Flex>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -92,33 +92,52 @@ export default function HomeOrdersTable({
|
||||
const isClosed = !!item.closed;
|
||||
const closedStr = isClosed ? " Closed" : "Open";
|
||||
|
||||
const dateStr =
|
||||
item.created_at
|
||||
? new Date(item.created_at).toLocaleString()
|
||||
: "Unknown creation time";
|
||||
const dateStr = item.created_at
|
||||
? new Date(item.created_at).toLocaleString()
|
||||
: "Unknown creation time";
|
||||
|
||||
return (
|
||||
<Space size={16}>
|
||||
<Icon path={mdiFood} size={1} style={getOrderIconStyle(isClosed)} />
|
||||
<Icon
|
||||
path={mdiFood}
|
||||
size={1}
|
||||
style={getOrderIconStyle(isClosed)}
|
||||
/>
|
||||
<Space direction="vertical" size={0}>
|
||||
<Space size={8} align="center">
|
||||
<Text strong>{item.title || item.id}</Text>
|
||||
{item.is_owner ? <Tag color="geekblue">Owner</Tag> : null}
|
||||
{state === "paid" ? <Tag color="green">Paid</Tag> : null}
|
||||
{state === "unpaid" ? (
|
||||
<Tag color="volcano">Unpaid</Tag>
|
||||
) : null}
|
||||
{state === "pending" ? <Tag color="blue">Pending</Tag> : null}
|
||||
<Space size={0} align="center">
|
||||
{item.is_owner ? <Tag color="geekblue">Owner</Tag> : null}
|
||||
{item.is_owner && item.has_unpaid_submissions ? (
|
||||
<Tag color="volcano">Open payments</Tag>
|
||||
) : null}
|
||||
{state === "paid" ? <Tag color="green">Paid</Tag> : null}
|
||||
{state === "unpaid" ? (
|
||||
<Tag color="volcano">Unpaid</Tag>
|
||||
) : null}
|
||||
{state === "pending" ? (
|
||||
<Tag color="blue">Pending</Tag>
|
||||
) : null}
|
||||
</Space>
|
||||
</Space>
|
||||
<Text type="secondary">
|
||||
{<Tooltip title={`Order is ${closedStr.toLocaleLowerCase()}`}>{closedStr}</Tooltip>}{" • "}
|
||||
{<Tooltip title={`Created at: ${dateStr}`}>{dateStr}</Tooltip>}
|
||||
{
|
||||
<Tooltip
|
||||
title={`Order is ${closedStr.toLocaleLowerCase()}`}
|
||||
>
|
||||
{closedStr}
|
||||
</Tooltip>
|
||||
}
|
||||
{" • "}
|
||||
{
|
||||
<Tooltip title={`Created at: ${dateStr}`}>
|
||||
{dateStr}
|
||||
</Tooltip>
|
||||
}
|
||||
{item.is_participant && formatted && (
|
||||
<>
|
||||
{" • "}
|
||||
<Tooltip title="Your order">
|
||||
{formatted}
|
||||
</Tooltip>
|
||||
<Tooltip title="Your order">{formatted}</Tooltip>
|
||||
</>
|
||||
)}
|
||||
</Text>
|
||||
|
||||
@@ -73,6 +73,7 @@ export type Order = OrderBase & {
|
||||
is_owner: boolean;
|
||||
is_participant: boolean;
|
||||
};
|
||||
has_unpaid_submissions?: boolean;
|
||||
};
|
||||
|
||||
export type OrderAdminView = OrderBase & {
|
||||
|
||||
@@ -59,10 +59,8 @@ export default function AdminView({ orderId }: { orderId: string }) {
|
||||
const [savingStatusKey, setSavingStatusKey] = useState<string | null>(null);
|
||||
const [updatingOrderStatus, setUpdatingOrderStatus] = useState(false);
|
||||
const [deletingOrder, setDeletingOrder] = useState(false);
|
||||
const [submissionsPage, setSubmissionsPage] = useState(1);
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [selectedSubmissionState, setSelectedSubmissionState] = useState<"all" | "pending" | "unpaid" | "paid">("all");
|
||||
const SUBMISSIONS_PAGE_SIZE = 8;
|
||||
|
||||
const getSubmissionState = (submission: Submission): SubmissionStatus => {
|
||||
if (submission?.paid) {
|
||||
@@ -263,17 +261,6 @@ export default function AdminView({ orderId }: { orderId: string }) {
|
||||
};
|
||||
}, [refreshSubmissions]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
const maxPage = Math.max(1, Math.ceil(data.submissions.length / SUBMISSIONS_PAGE_SIZE));
|
||||
if (submissionsPage > maxPage) {
|
||||
setSubmissionsPage(maxPage);
|
||||
}
|
||||
}, [data, submissionsPage]);
|
||||
|
||||
const filteredSubmissions = useMemo(() => {
|
||||
if (!data?.submissions) {
|
||||
return [];
|
||||
@@ -312,10 +299,6 @@ export default function AdminView({ orderId }: { orderId: string }) {
|
||||
setSelectedRowKeys((previous) => previous.filter((id) => visibleIds.has(id)));
|
||||
}, [filteredSubmissions]);
|
||||
|
||||
useEffect(() => {
|
||||
setSubmissionsPage(1);
|
||||
}, [searchQuery, selectedSubmissionState]);
|
||||
|
||||
const selected = filteredSubmissions.filter((submission: any) =>
|
||||
selectedRowKeys.includes(submission.id),
|
||||
);
|
||||
@@ -357,10 +340,6 @@ export default function AdminView({ orderId }: { orderId: string }) {
|
||||
const totalEstimatedText = hasAnyEstimatedValue
|
||||
? formatEstimatedTotal(totalEstimatedValue)
|
||||
: null;
|
||||
const pagedSubmissions = filteredSubmissions.slice(
|
||||
(submissionsPage - 1) * SUBMISSIONS_PAGE_SIZE,
|
||||
submissionsPage * SUBMISSIONS_PAGE_SIZE,
|
||||
);
|
||||
|
||||
if (pageError || loading) {
|
||||
return (
|
||||
@@ -417,6 +396,14 @@ export default function AdminView({ orderId }: { orderId: string }) {
|
||||
onImportConfig={handleImportConfig}
|
||||
/>
|
||||
|
||||
<AdminControlCenterCard
|
||||
isClosed={!!data?.closed}
|
||||
updatingOrderStatus={updatingOrderStatus}
|
||||
deletingOrder={deletingOrder}
|
||||
onToggleClosed={updateOrderClosedStatus}
|
||||
onDeleteOrder={deleteOrder}
|
||||
/>
|
||||
|
||||
<AdminSubmissionsCard
|
||||
searchQuery={searchQuery}
|
||||
selectedSubmissionState={selectedSubmissionState}
|
||||
@@ -429,25 +416,13 @@ export default function AdminView({ orderId }: { orderId: string }) {
|
||||
onOpenMailto={openSubmissionEmailDraft}
|
||||
selectedRowKeys={selectedRowKeys}
|
||||
onSelectedRowKeysChange={setSelectedRowKeys}
|
||||
pagedSubmissions={pagedSubmissions}
|
||||
submissions={filteredSubmissions}
|
||||
deletingId={deletingId}
|
||||
savingStatusKey={savingStatusKey}
|
||||
onDeleteSubmission={deleteAsAdmin}
|
||||
onUpdateSubmissionStatus={updateSubmissionStatus}
|
||||
totalEstimatedText={totalEstimatedText}
|
||||
selectedCount={selected.length}
|
||||
submissionsPage={submissionsPage}
|
||||
pageSize={SUBMISSIONS_PAGE_SIZE}
|
||||
totalCount={filteredSubmissions.length}
|
||||
onSubmissionsPageChange={setSubmissionsPage}
|
||||
/>
|
||||
|
||||
<AdminControlCenterCard
|
||||
isClosed={!!data?.closed}
|
||||
updatingOrderStatus={updatingOrderStatus}
|
||||
deletingOrder={deletingOrder}
|
||||
onToggleClosed={updateOrderClosedStatus}
|
||||
onDeleteOrder={deleteOrder}
|
||||
/>
|
||||
</Space>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user