mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-31 06:59:07 +02:00
Remove option to reset dates
This is done automatically now for legacy polls that need it
This commit is contained in:
parent
c9aaddf4cc
commit
e44afd84cc
5 changed files with 15 additions and 160 deletions
|
@ -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 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 { Placement } from "@popperjs/core";
|
||||||
import { useMutation, useQueryClient } from "react-query";
|
import { format } from "date-fns";
|
||||||
import axios from "axios";
|
import { useTranslation } from "next-i18next";
|
||||||
import { usePlausible } from "next-plausible";
|
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"));
|
const PollOptionsForm = React.lazy(() => import("../forms/poll-options-form"));
|
||||||
|
|
||||||
|
@ -28,34 +24,6 @@ const ManagePoll: React.VoidFunctionComponent<{
|
||||||
}> = ({ targetTimeZone, placement }) => {
|
}> = ({ targetTimeZone, placement }) => {
|
||||||
const { t } = useTranslation("app");
|
const { t } = useTranslation("app");
|
||||||
const poll = usePoll();
|
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 } =
|
const { mutate: updatePollMutation, isLoading: isUpdating } =
|
||||||
useUpdatePollMutation();
|
useUpdatePollMutation();
|
||||||
|
@ -157,7 +125,6 @@ const ManagePoll: React.VoidFunctionComponent<{
|
||||||
<div>
|
<div>
|
||||||
{changeOptionsModalContextHolder}
|
{changeOptionsModalContextHolder}
|
||||||
{changePollDetailsModalContextHolder}
|
{changePollDetailsModalContextHolder}
|
||||||
{resetModalContext}
|
|
||||||
<Dropdown
|
<Dropdown
|
||||||
placement={placement}
|
placement={placement}
|
||||||
trigger={<Button icon={<Cog />}>Manage</Button>}
|
trigger={<Button icon={<Cog />}>Manage</Button>}
|
||||||
|
@ -241,15 +208,6 @@ const ManagePoll: React.VoidFunctionComponent<{
|
||||||
onClick={() => updatePollMutation({ closed: true })}
|
onClick={() => updatePollMutation({ closed: true })}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{poll.legacy && poll.options[0].value.indexOf("T") === -1 ? (
|
|
||||||
<DropdownItem
|
|
||||||
icon={Refresh}
|
|
||||||
label="Reset dates"
|
|
||||||
onClick={() => {
|
|
||||||
openResetModal();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,19 +15,6 @@ const Support: React.VoidFunctionComponent = () => {
|
||||||
<h1 className="text-5xl">Support</h1>
|
<h1 className="text-5xl">Support</h1>
|
||||||
<div className="lg:flex py-16">
|
<div className="lg:flex py-16">
|
||||||
<div className="grow mb-8">
|
<div className="grow mb-8">
|
||||||
<h2 className="text-3xl mb-4">Troubleshooting</h2>
|
|
||||||
<Disclosure as="div" className="bg-slate-50 p-2 rounded-lg mb-4">
|
|
||||||
<Disclosure.Button className="font-medium text-lg py-2 px-3 rounded-lg active:bg-slate-200 block w-full text-left font-slate hover:text-indigo-500 hover:bg-slate-100 cursor-pointer">
|
|
||||||
<Trans t={t} i18nKey="wrongDaysShownQuestion" />
|
|
||||||
</Disclosure.Button>
|
|
||||||
<Disclosure.Panel className="text py-2 px-3">
|
|
||||||
<Trans
|
|
||||||
t={t}
|
|
||||||
i18nKey="wrongDaysShownAnswer"
|
|
||||||
components={{ b: <strong /> }}
|
|
||||||
/>
|
|
||||||
</Disclosure.Panel>
|
|
||||||
</Disclosure>
|
|
||||||
<h2 className="text-3xl mb-4">General</h2>
|
<h2 className="text-3xl mb-4">General</h2>
|
||||||
<Disclosure as="div" className="bg-slate-50 p-2 rounded-lg mb-4">
|
<Disclosure as="div" className="bg-slate-50 p-2 rounded-lg mb-4">
|
||||||
<Disclosure.Button className="font-medium text-lg py-2 px-3 rounded-lg active:bg-slate-200 block w-full text-left font-slate hover:text-indigo-500 hover:bg-slate-100 cursor-pointer">
|
<Disclosure.Button className="font-medium text-lg py-2 px-3 rounded-lg active:bg-slate-200 block w-full text-left font-slate hover:text-indigo-500 hover:bg-slate-100 cursor-pointer">
|
||||||
|
|
|
@ -11,7 +11,6 @@ export default async function handler(
|
||||||
res: NextApiResponse<GetPollApiResponse>,
|
res: NextApiResponse<GetPollApiResponse>,
|
||||||
) {
|
) {
|
||||||
const urlId = getQueryParam(req, "urlId");
|
const urlId = getQueryParam(req, "urlId");
|
||||||
const reset = req.query.reset;
|
|
||||||
|
|
||||||
const client = await getMongoClient();
|
const client = await getMongoClient();
|
||||||
if (!client) {
|
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) => ({
|
const newParticipants = legacyPoll.participants?.map((legacyParticipant) => ({
|
||||||
name: legacyParticipant.name,
|
name: legacyParticipant.name,
|
||||||
id: legacyParticipant._id.toString(),
|
id: legacyParticipant._id.toString(),
|
||||||
|
|
|
@ -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<GetPollApiResponse>,
|
|
||||||
) {
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -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 <a>support@rallly.co</a> to attempt to recover it.",
|
"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 <a>support@rallly.co</a> to attempt to recover it.",
|
||||||
"howDoIShareQuestion": "How do I share my poll with my participants?",
|
"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…",
|
"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 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?",
|
"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."
|
"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."
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue