diff --git a/client/src/components/AdminView.tsx b/client/src/components/AdminView.tsx
index 01b9ca3..8b35bb4 100644
--- a/client/src/components/AdminView.tsx
+++ b/client/src/components/AdminView.tsx
@@ -1,4 +1,4 @@
-import { useContext, useState } from "react";
+import { useContext, useState, useEffect } from "react";
// components
import { ConfirmationModal, PageFooter } from "@/components";
@@ -7,7 +7,7 @@ import { ConfirmationModal, PageFooter } from "@/components";
import { backendAPI } from "@/utils/backendAPI";
// context
-import { GlobalDispatchContext } from "@/context/GlobalContext";
+import { GlobalDispatchContext, GlobalStateContext } from "@/context/GlobalContext";
import { SET_POLL } from "@/context/types";
interface PollFormInputs {
@@ -41,6 +41,7 @@ export const AdminView = () => {
});
const [isSubmitting, setIsSubmitting] = useState(false);
const [modalType, setModalType] = useState<"save" | "reset" | null>(null);
+ const { poll } = useContext(GlobalStateContext);
function handleToggleShowConfirmationModal() {
setShowConfirmationModal(!showConfirmationModal);
@@ -123,6 +124,22 @@ export const AdminView = () => {
setShowConfirmationModal(true);
};
+ useEffect(() => {
+ if (!poll) return;
+ // pull the question + the answers array
+ const { question, answers, displayMode } = poll;
+
+ setFormData({
+ question,
+ answer1: answers[0] || "",
+ answer2: answers[1] || "",
+ answer3: answers[2] || "",
+ answer4: answers[3] || "",
+ answer5: answers[4] || "",
+ displayMode: displayMode === "count" ? "count" : "percentage",
+ });
+ }, [poll]);
+
return (
Create or Update Poll
diff --git a/server/controllers/handleGetPoll.ts b/server/controllers/handleGetPoll.ts
index 86ce76e..5836884 100644
--- a/server/controllers/handleGetPoll.ts
+++ b/server/controllers/handleGetPoll.ts
@@ -4,11 +4,26 @@ import { errorHandler, getCredentials, getDroppedAsset } from "../utils/index.js
export const handleGetPoll = async (req: Request, res: Response) => {
try {
const credentials = getCredentials(req.query);
+ const { profileId, urlSlug } = credentials;
const droppedAsset = await getDroppedAsset(credentials);
await droppedAsset.fetchDataObject();
+ await droppedAsset.updateDataObject(
+ {},
+ {
+ analytics: [
+ {
+ analyticName: "starts",
+ profileId,
+ urlSlug,
+ uniqueKey: profileId,
+ },
+ ],
+ },
+ );
+
return res.json({ poll: droppedAsset.dataObject, success: true });
} catch (error) {
return errorHandler({
diff --git a/server/controllers/handleUpdatePoll.ts b/server/controllers/handleUpdatePoll.ts
index 8294485..27a417f 100644
--- a/server/controllers/handleUpdatePoll.ts
+++ b/server/controllers/handleUpdatePoll.ts
@@ -8,7 +8,7 @@ import { errorHandler, getCredentials, getDroppedAsset } from "../utils/index.js
export const handleUpdatePoll = async (req: Request, res: Response) => {
try {
const credentials = getCredentials(req.query);
- const { assetId } = credentials;
+ const { assetId, profileId, urlSlug } = credentials;
const { question, answer1, answer2, answer3, answer4, answer5, displayMode } = req.body;
const droppedAsset = await getDroppedAsset(credentials);
@@ -28,7 +28,17 @@ export const handleUpdatePoll = async (req: Request, res: Response) => {
},
results: {},
},
- { lock: { lockId, releaseLock: true } },
+ {
+ lock: { lockId, releaseLock: true },
+ analytics: [
+ {
+ analyticName: "updates",
+ profileId,
+ urlSlug,
+ uniqueKey: profileId,
+ },
+ ],
+ },
);
await droppedAsset.fetchDataObject();
diff --git a/server/controllers/handleVote.ts b/server/controllers/handleVote.ts
index 5d2a25c..30f5bb4 100644
--- a/server/controllers/handleVote.ts
+++ b/server/controllers/handleVote.ts
@@ -5,7 +5,7 @@ export const handleVote = async (req: Request, res: Response) => {
try {
// Extract credentials and vote details
const credentials = getCredentials(req.query);
- const { assetId } = credentials;
+ const { assetId, urlSlug } = credentials;
const { optionId, profileId } = req.body;
if (optionId === undefined || !profileId) {
return res.status(400).json({ success: false, message: "optionId and profileId are required" });
@@ -42,7 +42,17 @@ export const handleVote = async (req: Request, res: Response) => {
options: newOptions,
results: newResults,
},
- { lock: { lockId, releaseLock: true } },
+ {
+ lock: { lockId, releaseLock: true },
+ analytics: [
+ {
+ analyticName: "completions",
+ profileId,
+ urlSlug,
+ uniqueKey: profileId,
+ },
+ ],
+ },
);
await droppedAsset.fetchDataObject();