Merge branch 'main' into adilallo/fix/CR-279-save-email-review-card
This commit is contained in:
commit
8ec0be18bc
74 files changed
+2488
-630
No files matched your search
@@ -15,11 +15,10 @@ import {
|
||||
} from "../../../../lib/create/shareChannels";
|
||||
import {
|
||||
buildPublicRuleUrl,
|
||||
downloadStoredRuleAsMarkdown,
|
||||
downloadStoredRuleAsPdf,
|
||||
downloadTextFile,
|
||||
exportFilenameBase,
|
||||
exportStoredRuleAsCsv,
|
||||
exportStoredRuleAsMarkdown,
|
||||
printStoredRule,
|
||||
type RuleExportFormat,
|
||||
} from "../../../../lib/create/ruleExport";
|
||||
|
||||
export type CompletedFlowActionBanner = {
|
||||
@@ -101,7 +100,7 @@ export function useCompletedRuleShareExport({
|
||||
sharePublishedRuleViaSignal: () => Promise<void>;
|
||||
sharePublishedRuleViaSlack: () => Promise<void>;
|
||||
sharePublishedRuleViaDiscord: () => Promise<void>;
|
||||
onSelectExportFormat: (_format: "pdf" | "csv" | "markdown") => void;
|
||||
onSelectExportFormat: (_format: RuleExportFormat) => void;
|
||||
} {
|
||||
const t = useTranslation("create.reviewAndComplete.completed");
|
||||
|
||||
@@ -318,7 +317,7 @@ export function useCompletedRuleShareExport({
|
||||
]);
|
||||
|
||||
const onSelectExportFormat = useCallback(
|
||||
(format: "pdf" | "csv" | "markdown") => {
|
||||
(format: RuleExportFormat) => {
|
||||
if (typeof window === "undefined") return;
|
||||
const rule = readLastPublishedRule();
|
||||
if (!rule) {
|
||||
@@ -331,34 +330,29 @@ export function useCompletedRuleShareExport({
|
||||
return;
|
||||
}
|
||||
|
||||
const base = exportFilenameBase(rule);
|
||||
const origin = window.location.origin;
|
||||
try {
|
||||
if (format === "pdf") {
|
||||
downloadStoredRuleAsPdf(rule);
|
||||
} else if (format === "csv") {
|
||||
const csv = exportStoredRuleAsCsv(rule);
|
||||
downloadTextFile(
|
||||
`${base}-community-rule.csv`,
|
||||
csv,
|
||||
"text/csv;charset=utf-8",
|
||||
);
|
||||
downloadStoredRuleAsPdf(rule, origin);
|
||||
} else if (format === "print") {
|
||||
const opened = printStoredRule(rule, origin);
|
||||
if (!opened) {
|
||||
setActionBanner({
|
||||
key: "completedPrintBlocked",
|
||||
status: "warning",
|
||||
title: t("printBlockedTitle"),
|
||||
description: t("printBlockedDescription"),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const md = exportStoredRuleAsMarkdown(rule);
|
||||
downloadTextFile(
|
||||
`${base}-community-rule.md`,
|
||||
md,
|
||||
"text/markdown;charset=utf-8",
|
||||
);
|
||||
downloadStoredRuleAsMarkdown(rule, origin);
|
||||
}
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error && e.message === "exportEmptyDocument";
|
||||
} catch {
|
||||
setActionBanner({
|
||||
key: "completedExportFailed",
|
||||
status: "danger",
|
||||
title: msg ? t("exportEmptyDocumentTitle") : t("exportFailedTitle"),
|
||||
description: msg
|
||||
? t("exportEmptyDocumentDescription")
|
||||
: t("exportFailedDescription"),
|
||||
title: t("exportFailedTitle"),
|
||||
description: t("exportFailedDescription"),
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -196,6 +196,9 @@ export function useCreateFlowFinalize({
|
||||
title,
|
||||
summary: summary ?? null,
|
||||
document: ruleDocument,
|
||||
...(publishResult.createdAt
|
||||
? { finishedAt: publishResult.createdAt }
|
||||
: {}),
|
||||
});
|
||||
if (isGuest) {
|
||||
writePendingKeepRuleLogin();
|
||||
|
||||
@@ -4,16 +4,17 @@ import { useState, useEffect } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import CommunityRule from "../../../../components/type/CommunityRule";
|
||||
import type { CommunityRuleSection } from "../../../../components/type/CommunityRule/CommunityRule.types";
|
||||
import Link from "next/link";
|
||||
import Alert from "../../../../components/modals/Alert";
|
||||
import AskOrganizerInquiryModal from "../../../../components/modals/AskOrganizerInquiry";
|
||||
import InlineTextButton from "../../../../components/buttons/InlineTextButton";
|
||||
import { useMessages } from "../../../../contexts/MessagesContext";
|
||||
import { fetchPublishedRuleDetail } from "../../../../../lib/create/api";
|
||||
import { parsePublishedDocumentForCommunityRuleDisplay } from "../../../../../lib/create/publishedDocumentToDisplaySections";
|
||||
import {
|
||||
finishedAtIso,
|
||||
readLastPublishedRule,
|
||||
writeLastPublishedRule,
|
||||
} from "../../../../../lib/create/lastPublishedRule";
|
||||
import { ASK_ORGANIZER_HASH } from "../../../../../lib/sharePaths";
|
||||
import { useCreateFlowMdUp } from "../../hooks/useCreateFlowMdUp";
|
||||
import { CreateFlowHeaderLockup } from "../../components/CreateFlowHeaderLockup";
|
||||
import {
|
||||
@@ -99,7 +100,6 @@ export function CompletedScreen() {
|
||||
/** Latch: toast copy should survive `router.replace` after we strip `?celebrate=1`. */
|
||||
const [showCelebrateToast] = useState(celebrateInUrl);
|
||||
const [showCopiedReady] = useState(copiedInUrl);
|
||||
const [askOrganizerOpen, setAskOrganizerOpen] = useState(false);
|
||||
const [headerTitle, setHeaderTitle] = useState(initial.headerTitle);
|
||||
const [headerDescription, setHeaderDescription] = useState<
|
||||
string | undefined
|
||||
@@ -124,11 +124,13 @@ export function CompletedScreen() {
|
||||
return;
|
||||
}
|
||||
const doc = detail.rule.document as Record<string, unknown>;
|
||||
const finishedAt = finishedAtIso(detail.rule.createdAt);
|
||||
writeLastPublishedRule({
|
||||
id: detail.rule.id,
|
||||
title: detail.rule.title,
|
||||
summary: detail.rule.summary,
|
||||
document: doc,
|
||||
...(finishedAt ? { finishedAt } : {}),
|
||||
});
|
||||
const parsed = parsePublishedDocumentForCommunityRuleDisplay(doc);
|
||||
if (parsed.length === 0) {
|
||||
@@ -210,13 +212,17 @@ export function CompletedScreen() {
|
||||
/>
|
||||
{headerTitle && !surfaceCopied ? (
|
||||
<p className="mt-[var(--space-400)] max-w-[640px] text-small-paragraph text-[var(--color-content-invert-secondary)]">
|
||||
{completed.askOrganizerLead}{" "}
|
||||
<InlineTextButton
|
||||
className="text-small-paragraph text-[var(--color-content-invert-primary)]"
|
||||
onClick={() => setAskOrganizerOpen(true)}
|
||||
{completed.askOrganizerLead ? (
|
||||
<>
|
||||
{completed.askOrganizerLead}{" "}
|
||||
</>
|
||||
) : null}
|
||||
<Link
|
||||
href={`/#${ASK_ORGANIZER_HASH}`}
|
||||
className="text-small-paragraph text-[var(--color-content-invert-primary)] underline"
|
||||
>
|
||||
{completed.askOrganizerLink}
|
||||
</InlineTextButton>
|
||||
</Link>
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -261,10 +267,6 @@ export function CompletedScreen() {
|
||||
</div>
|
||||
</div>
|
||||
{toast}
|
||||
<AskOrganizerInquiryModal
|
||||
isOpen={askOrganizerOpen}
|
||||
onClose={() => setAskOrganizerOpen(false)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user