Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
Reset legacy dates without deleting poll
Luke Vellae1e691a45d2a
diff --git a/components/poll/manage-poll.tsx b/components/poll/manage-poll.tsxindex 642a2a415..efb7756ac 100644--- a/components/poll/manage-poll.tsx+++ b/components/poll/manage-poll.tsx@@ -18,6 +18,7 @@ import Button from "@/components/button";import { Placement } from "@popperjs/core";import { useMutation, useQueryClient } from "react-query";import axios from "axios";+import { usePlausible } from "next-plausible";const PollOptionsForm = React.lazy(() => import("../forms/poll-options-form"));@@ -27,8 +28,9 @@ const ManagePoll: React.VoidFunctionComponent<{}> = ({ targetTimeZone, placement }) => {const { t } = useTranslation("app");const poll = usePoll();+ const plausible = usePlausible();const queryClient = useQueryClient();- const { mutate: resetPoll } = useMutation(+ const { mutate: resetDates } = useMutation(async () => {await axios.get(`/api/legacy/${poll.urlId}?reset=true`);},@@ -42,22 +44,15 @@ const ManagePoll: React.VoidFunctionComponent<{const [resetModalContext, openResetModal] = useModal({overlayClosable: true,title: "Are you sure?",- description: (- <>- This will reset the poll to how it was before it was transferred to the- new version.- <em className="block mt-2">- Any changes (including votes or comments) that were done in the new- version will be lost.- </em>- </>- ),+ description:+ "This will reset the dates to how they were before the upgrade.",okText: "Reset",okButtonProps: {type: "danger",},onOk: () => {- resetPoll();+ plausible("Reset dates");+ resetDates();},cancelText: "Cancel",});@@ -247,7 +242,7 @@ const ManagePoll: React.VoidFunctionComponent<{{poll.legacy && poll.options[0].value.indexOf("T") === -1 ? (<DropdownItemicon={Refresh}- label="Reset poll"+ label="Reset dates"onClick={() => {openResetModal();}}diff --git a/pages/api/legacy/[urlId].ts b/pages/api/legacy/[urlId].tsindex cb38fd781..66b6325e8 100644--- a/pages/api/legacy/[urlId].ts+++ b/pages/api/legacy/[urlId].ts@@ -80,6 +80,69 @@ export default async function handler(});}+ if (reset) {+ const existingOptions = await prisma.option.findMany({+ where: { pollId: legacyPoll._id },+ orderBy: {+ value: "asc",+ },+ });++ if (!existingOptions) {+ return res.status(400).end();+ }++ const promises = [];+ for (let i = 0; i < existingOptions.length; i++) {+ promises.push(+ prisma.option.update({+ where: { id: existingOptions[i].id },+ data: {+ value: newOptions[i].value,+ },+ }),+ );+ }+ await prisma.$transaction(promises);++ const poll = await prisma.poll.findUnique({+ where: {+ urlId: legacyPoll._id,+ },+ include: {+ options: {+ include: {+ votes: true,+ },+ },+ participants: {+ include: {+ votes: true,+ },+ orderBy: [+ {+ createdAt: "desc",+ },+ { name: "desc" },+ ],+ },+ user: true,+ links: true,+ },+ });++ if (!poll) {+ return res.status(404);+ }++ return res.json({+ ...exclude(poll, "verificationCode"),+ role: "admin",+ urlId: poll.urlId,+ pollId: poll.urlId,+ });+ }+const newParticipants = legacyPoll.participants?.map((legacyParticipant) => ({name: legacyParticipant.name,id: legacyParticipant._id.toString(),@@ -99,10 +162,6 @@ export default async function handler(});});- if (reset) {- await prisma.poll.delete({ where: { urlId: legacyPoll._id } });- }-const poll = await prisma.poll.create({data: {legacy: true,diff --git a/public/locales/en/support.json b/public/locales/en/support.jsonindex 06894170b..17c522d3f 100644--- a/public/locales/en/support.json+++ b/public/locales/en/support.json@@ -15,7 +15,7 @@"howDoIShareQuestion": "How do I share my poll with my participants?","howDoIShareAnswer": "To share your poll, click on the <b>Share</b> button next to the title of your poll and copy the participant link. You can share this link with your participants through your own channels such as email, whatsapp, facebook etc…","wrongDaysShownQuestion": "My poll is now showing the wrong dates. What can I do?",- "wrongDaysShownAnswer": "A number of users have been affected by this bug which is caused by the previous version storing the incorrect dates in the database. However when the dates are adjusted for the user's time zone they appear to be correct. If you notice that your days have shifted you can reset your poll by clicking <b>Manage</b> > <b>Reset Poll</b>. This will refetch the data from the legacy database and revert it to how it was before the transfer. <b>Any changes (including votes or comments) made after the poll was transferred will be lost</b>.",+ "wrongDaysShownAnswer": "A number of users have been affected by this bug which is caused by the previous version storing the incorrect dates in the database. However when the dates are adjusted for the user's time zone they appear to be correct. If you notice that your days have shifted you can reset your dates by clicking <b>Manage</b> > <b>Reset dates</b>. This will refetch the data from the legacy database and revert the dates to how they were before the upgrade.","contributeQuestion": "How can I contribute?","contributeAnswer": "Rallly is 100% self-funded so the best way to contribute is to become a <a>sponsor</a>. This money will go towards paying for hosting and will support future development of this website."}