From e44afd84cc086bf3d7e8f16417463366617e00f2 Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Tue, 12 Apr 2022 20:07:09 +0100 Subject: [PATCH] Remove option to reset dates This is done automatically now for legacy polls that need it --- components/poll/manage-poll.tsx | 72 +++++++------------------------ components/support.tsx | 13 ------ pages/api/legacy/[urlId].ts | 64 --------------------------- pages/api/legacy/[urlId]/reset.ts | 24 ----------- public/locales/en/support.json | 2 - 5 files changed, 15 insertions(+), 160 deletions(-) delete mode 100644 pages/api/legacy/[urlId]/reset.ts diff --git a/components/poll/manage-poll.tsx b/components/poll/manage-poll.tsx index 343bde7de..efde69aaa 100644 --- a/components/poll/manage-poll.tsx +++ b/components/poll/manage-poll.tsx @@ -1,24 +1,20 @@ -import * as React from "react"; -import Dropdown, { DropdownItem } from "../dropdown"; -import { usePoll } from "../use-poll"; -import Pencil from "@/components/icons/pencil-alt.svg"; -import Table from "@/components/icons/table.svg"; -import Refresh from "@/components/icons/refresh.svg"; -import Save from "@/components/icons/save.svg"; -import Cog from "@/components/icons/cog.svg"; -import LockOpen from "@/components/icons/lock-open.svg"; -import LockClosed from "@/components/icons/lock-closed.svg"; -import { useTranslation } from "next-i18next"; -import { format } from "date-fns"; -import { decodeDateOption, encodeDateOption } from "utils/date-time-utils"; -import { useModal } from "../modal"; -import { useUpdatePollMutation } from "./mutations"; -import { PollDetailsForm } from "../forms"; import Button from "@/components/button"; +import Cog from "@/components/icons/cog.svg"; +import LockClosed from "@/components/icons/lock-closed.svg"; +import LockOpen from "@/components/icons/lock-open.svg"; +import Pencil from "@/components/icons/pencil-alt.svg"; +import Save from "@/components/icons/save.svg"; +import Table from "@/components/icons/table.svg"; import { Placement } from "@popperjs/core"; -import { useMutation, useQueryClient } from "react-query"; -import axios from "axios"; -import { usePlausible } from "next-plausible"; +import { format } from "date-fns"; +import { useTranslation } from "next-i18next"; +import * as React from "react"; +import { decodeDateOption, encodeDateOption } from "utils/date-time-utils"; +import Dropdown, { DropdownItem } from "../dropdown"; +import { PollDetailsForm } from "../forms"; +import { useModal } from "../modal"; +import { usePoll } from "../use-poll"; +import { useUpdatePollMutation } from "./mutations"; const PollOptionsForm = React.lazy(() => import("../forms/poll-options-form")); @@ -28,34 +24,6 @@ const ManagePoll: React.VoidFunctionComponent<{ }> = ({ targetTimeZone, placement }) => { const { t } = useTranslation("app"); const poll = usePoll(); - const plausible = usePlausible(); - const queryClient = useQueryClient(); - const { mutate: resetDates } = useMutation( - async () => { - await axios.get(`/api/legacy/${poll.urlId}/reset`); - }, - { - onSettled: () => { - queryClient.invalidateQueries(["getPoll", poll.urlId]); - }, - }, - ); - - const [resetModalContext, openResetModal] = useModal({ - overlayClosable: true, - title: "Are you sure?", - description: - "This will reset the dates to how they were before the upgrade.", - okText: "Reset", - okButtonProps: { - type: "danger", - }, - onOk: () => { - plausible("Reset dates"); - resetDates(); - }, - cancelText: "Cancel", - }); const { mutate: updatePollMutation, isLoading: isUpdating } = useUpdatePollMutation(); @@ -157,7 +125,6 @@ const ManagePoll: React.VoidFunctionComponent<{
{changeOptionsModalContextHolder} {changePollDetailsModalContextHolder} - {resetModalContext} }>Manage} @@ -241,15 +208,6 @@ const ManagePoll: React.VoidFunctionComponent<{ onClick={() => updatePollMutation({ closed: true })} /> )} - {poll.legacy && poll.options[0].value.indexOf("T") === -1 ? ( - { - openResetModal(); - }} - /> - ) : null}
); diff --git a/components/support.tsx b/components/support.tsx index ef2579e07..183a298c6 100644 --- a/components/support.tsx +++ b/components/support.tsx @@ -15,19 +15,6 @@ const Support: React.VoidFunctionComponent = () => {

Support

-

Troubleshooting

- - - - - - }} - /> - -

General

diff --git a/pages/api/legacy/[urlId].ts b/pages/api/legacy/[urlId].ts index 2471fe23b..92353e3a1 100644 --- a/pages/api/legacy/[urlId].ts +++ b/pages/api/legacy/[urlId].ts @@ -11,7 +11,6 @@ export default async function handler( res: NextApiResponse, ) { const urlId = getQueryParam(req, "urlId"); - const reset = req.query.reset; const client = await getMongoClient(); if (!client) { @@ -45,69 +44,6 @@ 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(), diff --git a/pages/api/legacy/[urlId]/reset.ts b/pages/api/legacy/[urlId]/reset.ts deleted file mode 100644 index 9609a53fc..000000000 --- a/pages/api/legacy/[urlId]/reset.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { GetPollApiResponse } from "api-client/get-poll"; -import { NextApiRequest, NextApiResponse } from "next"; -import { exclude, getQueryParam } from "utils/api-utils"; -import { resetDates } from "utils/legacy-utils"; - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse, -) { - const urlId = getQueryParam(req, "urlId"); - - const poll = await resetDates(urlId); - - if (!poll) { - return res.status(404); - } - - return res.json({ - ...exclude(poll, "verificationCode"), - role: "admin", - urlId: poll.urlId, - pollId: poll.urlId, - }); -} diff --git a/public/locales/en/support.json b/public/locales/en/support.json index 17c522d3f..1c759064b 100644 --- a/public/locales/en/support.json +++ b/public/locales/en/support.json @@ -14,8 +14,6 @@ "legacyPollsAnswer": "Legacy polls are stored in a different database but you can still access the poll with the same URL. The polls will be transferred over in to the new database when you first try to access it. If a poll has not been accessed for at least two months then it might no longer be available but you can contact support@rallly.co to attempt to recover it.", "howDoIShareQuestion": "How do I share my poll with my participants?", "howDoIShareAnswer": "To share your poll, click on the Share 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 dates by clicking Manage > Reset dates. 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 sponsor. This money will go towards paying for hosting and will support future development of this website." }