serverData.value?.notices?.filter((n) => n.level !== "survey") ?? [],
+);
+const surveyNotice = computed(() => serverData.value?.notices?.find((n) => n.level === "survey"));
+
+async function dismissSurvey() {
+ const noticeId = surveyNotice.value?.id;
+ if (noticeId === undefined) {
+ console.warn("No survey notice to dismiss");
+ return;
+ }
+ await dismissNotice(noticeId);
+ console.log(`Dismissed survey notice ${noticeId}`);
+}
+
+type TallyPopupOptions = {
+ key?: string;
+ layout?: "default" | "modal";
+ width?: number;
+ alignLeft?: boolean;
+ hideTitle?: boolean;
+ overlay?: boolean;
+ emoji?: {
+ text: string;
+ animation:
+ | "none"
+ | "wave"
+ | "tada"
+ | "heart-beat"
+ | "spin"
+ | "flash"
+ | "bounce"
+ | "rubber-band"
+ | "head-shake";
+ };
+ autoClose?: number;
+ showOnce?: boolean;
+ doNotShowAfterSubmit?: boolean;
+ customFormUrl?: string;
+ hiddenFields?: {
+ [key: string]: unknown;
+ };
+ onOpen?: () => void;
+ onClose?: () => void;
+ onPageView?: (page: number) => void;
+ onSubmit?: (payload: unknown) => void;
+};
+
+const popupOptions = computed(
+ () =>
+ ({
+ layout: "default",
+ width: 400,
+ autoClose: 2000,
+ hideTitle: true,
+ hiddenFields: {
+ username: auth.value?.user?.username,
+ user_id: auth.value?.user?.id,
+ user_email: auth.value?.user?.email,
+ server_id: serverData.value?.server_id,
+ loader: serverData.value?.loader,
+ game_version: serverData.value?.mc_version,
+ modpack_id: serverData.value?.project?.id,
+ modpack_name: serverData.value?.project?.title,
+ },
+ onOpen: () => console.log(`Opened survey notice: ${surveyNotice.value?.id}`),
+ onClose: async () => await dismissSurvey(),
+ onSubmit: (payload: any) => {
+ console.log("Form submitted:", payload);
+ },
+ }) satisfies TallyPopupOptions,
+);
+
+function showSurvey() {
+ if (!surveyNotice.value) {
+ console.warn("No survey notice to open");
+ return;
+ }
+
+ try {
+ if ((window as any).Tally?.openPopup) {
+ console.log(
+ `Opening Tally popup for survey notice ${surveyNotice.value?.id} (form ID: ${surveyNotice.value?.message})`,
+ );
+ (window as any).Tally.openPopup(surveyNotice.value?.message, popupOptions.value);
+ } else {
+ console.warn("Tally script not yet loaded");
+ }
+ } catch (e) {
+ console.error("Error opening Tally popup:", e);
+ }
+}
+
const connectWebSocket = () => {
if (!isMounted.value) return;
@@ -1006,6 +1097,10 @@ onMounted(() => {
}
},
);
+
+ if (surveyNotice.value) {
+ showSurvey();
+ }
});
onUnmounted(() => {
@@ -1030,6 +1125,15 @@ watch(
definePageMeta({
middleware: "auth",
});
+
+useHead({
+ script: [
+ {
+ src: "https://tally.so/widgets/embed.js",
+ defer: true,
+ },
+ ],
+});