First public commit
71
components/button/button.tsx
Normal file
|
@ -0,0 +1,71 @@
|
|||
import clsx from "clsx";
|
||||
import * as React from "react";
|
||||
|
||||
import SpinnerIcon from "../icons/spinner.svg";
|
||||
|
||||
export interface ButtonProps {
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
loading?: boolean;
|
||||
icon?: React.ReactElement;
|
||||
htmlType?: React.ButtonHTMLAttributes<HTMLButtonElement>["type"];
|
||||
type?: "default" | "primary" | "danger" | "link";
|
||||
form?: string;
|
||||
href?: string;
|
||||
rounded?: boolean;
|
||||
title?: string;
|
||||
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
||||
}
|
||||
|
||||
const Button: React.ForwardRefRenderFunction<HTMLButtonElement, ButtonProps> = (
|
||||
{
|
||||
children,
|
||||
loading,
|
||||
type = "default",
|
||||
htmlType = "button",
|
||||
className,
|
||||
icon,
|
||||
disabled,
|
||||
href,
|
||||
rounded,
|
||||
...passThroughProps
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
type={htmlType}
|
||||
className={clsx(
|
||||
{
|
||||
"btn-default": type === "default",
|
||||
"btn-primary": type === "primary",
|
||||
"btn-danger": type === "danger",
|
||||
"btn-link": type === "link",
|
||||
"btn-disabled": disabled,
|
||||
"rounded-full p-2 h-auto": rounded,
|
||||
"w-10 p-0": !children,
|
||||
},
|
||||
className,
|
||||
)}
|
||||
{...passThroughProps}
|
||||
disabled={disabled || loading}
|
||||
>
|
||||
{loading ? (
|
||||
<SpinnerIcon
|
||||
className={clsx("w-5 animate-spin inline-block", {
|
||||
"mr-2": !!children,
|
||||
})}
|
||||
/>
|
||||
) : icon ? (
|
||||
React.cloneElement(icon, {
|
||||
className: clsx("w-5 h-5", { "-ml-1 mr-2": !!children }),
|
||||
})
|
||||
) : null}
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.forwardRef(Button);
|
2
components/button/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export type { ButtonProps } from "./button";
|
||||
export { default } from "./button";
|
28
components/compact-button.tsx
Normal file
|
@ -0,0 +1,28 @@
|
|||
import * as React from "react";
|
||||
|
||||
export interface CompactButtonProps {
|
||||
icon?: React.ComponentType<{
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
}>;
|
||||
children?: React.ReactNode;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
const CompactButton: React.VoidFunctionComponent<CompactButtonProps> = ({
|
||||
icon: Icon,
|
||||
children,
|
||||
onClick,
|
||||
}) => {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="h-5 w-5 rounded-full hover:bg-gray-200 transition-colors active:text-gray-500 active:bg-gray-300 text-gray-400 bg-gray-100 inline-flex items-center justify-center"
|
||||
onClick={onClick}
|
||||
>
|
||||
{Icon ? <Icon className="w-3 h-3" /> : children}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
export default CompactButton;
|
49
components/cookie-consent.tsx
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { Transition } from "@headlessui/react";
|
||||
import Cookies from "js-cookie";
|
||||
import Link from "next/link";
|
||||
import * as React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { getPortal } from "utils/selectors";
|
||||
import CookiesIllustration from "./cookie-consent/cookies.svg";
|
||||
|
||||
const CookieConsentPopover: React.VoidFunctionComponent = () => {
|
||||
const [visible, setVisible] = React.useState(true);
|
||||
|
||||
return ReactDOM.createPortal(
|
||||
<Transition
|
||||
show={visible}
|
||||
appear={true}
|
||||
as="div"
|
||||
enter="transition transform delay-1000 duration-1000"
|
||||
enterFrom="opacity-0 translate-y-8"
|
||||
enterTo="opacity-100 translate-y-0"
|
||||
leave="duration-200"
|
||||
leaveFrom="opacity-100 translate-y-0"
|
||||
leaveTo="opacity-0 translate-y-8"
|
||||
className="bg-white z-50 p-4 pt-8 shadow-lg fixed rounded-lg w-60 text-sm bottom-8 right-8"
|
||||
>
|
||||
<CookiesIllustration className="absolute -top-6" />
|
||||
<div className="mb-3">
|
||||
Your privacy is important to us. We only use cookies to improve the
|
||||
browsing experience on this website.
|
||||
</div>
|
||||
<div className="flex space-x-6 items-center">
|
||||
<Link href="/privacy-policy">
|
||||
<a className="text-slate-400 hover:text-indigo-500">Privacy Policy</a>
|
||||
</Link>
|
||||
<button
|
||||
onClick={() => {
|
||||
Cookies.set("rallly_cookie_consent", "1", { expires: 365 });
|
||||
setVisible(false);
|
||||
}}
|
||||
className="grow text-white focus:ring-2 focus:ring-indigo-200 transition-all bg-indigo-500 hover:bg-indigo-500/90 active:bg-indigo-600/90 px-5 py-1 font-semibold shadow-sm rounded-md"
|
||||
>
|
||||
OK
|
||||
</button>
|
||||
</div>
|
||||
</Transition>,
|
||||
getPortal(),
|
||||
);
|
||||
};
|
||||
|
||||
export default CookieConsentPopover;
|
11
components/cookie-consent/cookies.svg
Normal file
|
@ -0,0 +1,11 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="71" height="44" fill="none" viewBox="0 0 71 44">
|
||||
<path fill="#BF8870" stroke="#644647" stroke-width="2" d="M42.5 21.5c0 5.722-1.803 10.584-5.22 14.134-3.414 3.546-8.526 5.874-15.316 6.366-6.742-.008-11.96-2.324-15.494-5.991C2.934 32.34 1.013 27.247 1 21.557 2.47 9.01 10.733 1 22 1c6.778 0 11.872 2.172 15.275 5.752C40.686 10.339 42.5 15.447 42.5 21.5z"/>
|
||||
<path fill="#fff" fill-opacity=".2" d="M3.893 28.215c.175.632 1.06.43 1.06-.226 0-12.719 9.84-23.03 21.976-23.03.748 0 1.026-.99.309-1.203A18.135 18.135 0 0022.046 3C11.527 3 3 11.994 3 23.09c0 1.463.408 3.373.893 5.125z"/>
|
||||
<path fill="#F0E0D2" stroke="#634647" stroke-width="2" d="M24.434 11c1.045 0 1.81-.82 1.92-1.765.115-.296.186-.637.122-.99a1.41 1.41 0 00-.724-.996 2.08 2.08 0 00-.784-.228C24.767 7 24.57 7 24.448 7h-.014c-1.131 0-1.934.96-1.934 2s.803 2 1.934 2zM10.5 25a3 3 0 002.99-2.755c.234-.525.358-1.066.257-1.59-.127-.656-.558-1.067-1.001-1.295-.41-.21-.866-.288-1.229-.324-.367-.036-.733-.036-1-.036H10.5a3 3 0 100 6zM22.963 36.678a3 3 0 004.018.624c.556-.144 1.056-.383 1.404-.79.434-.507.487-1.1.39-1.588-.091-.452-.314-.858-.512-1.164-.2-.309-.429-.596-.595-.805l-.01-.013a3 3 0 10-4.695 3.736z"/>
|
||||
<path fill="#845556" stroke="#634647" stroke-width="2" d="M37.044 19.802a3 3 0 00-.6-4.022c-.303-.488-.68-.894-1.172-1.105-.614-.264-1.195-.138-1.633.1-.404.222-.725.556-.958.835-.236.284-.442.587-.592.809l-.01.013a3 3 0 104.965 3.37z"/>
|
||||
<path stroke="#634647" stroke-linecap="round" stroke-width="2" d="M30.5 27.754l2.793 2.793M23.5 21.5c1-1.5 1-1.5 3.126-2.414M11.5 10.978s2.5 0 3.622 1.576M14.5 33.304s0-1.804 1.537-3.639"/>
|
||||
<path fill="#EAAC89" stroke="#634647" stroke-linejoin="round" stroke-width="2" d="M36.503 5.02c3.24-2.622 7.309-3.92 11.865-3.873a.379.379 0 01.077.104.98.98 0 01.105.577 4.5 4.5 0 002.429 4.693 4.517 4.517 0 001.272 1.542c.207.16.34.493.3.753A4.5 4.5 0 0057 14c.648 0 1.429.312 1.897.758a4.488 4.488 0 003.788 1.19c.26-.04.593.094.753.3a4.494 4.494 0 005.133 1.47c.197-.073.505-.086.756-.01a.522.522 0 01.187.087c.407 2.624.39 5.542-.116 8.734-1.543 6.564-4.985 11.117-9.36 13.724-4.378 2.609-9.775 3.32-15.318 2.038-11.884-4.288-17.803-14.156-15.238-25.128 1.285-5.5 3.774-9.514 7.022-12.142zm11.85-3.882s.004 0 .011.006c-.007-.003-.01-.005-.01-.006zm21.173 16.674s-.004-.003-.008-.012c.007.007.01.012.008.012z"/>
|
||||
<path fill="#fff" fill-opacity=".2" d="M30.893 27.215c.175.632 1.06.43 1.06-.226C31.953 14.27 35.363 4.5 47.5 4.5c.143 0 .217-.087.247-.22.165-.731.002-1.78-.747-1.78-10.519 0-17 8.494-17 19.59 0 1.463.408 3.373.893 5.125z"/>
|
||||
<path fill="#845556" stroke="#634647" stroke-width="2" d="M41.634 15.72c.238-1.017-.387-1.949-1.282-2.271-.262-.179-.577-.325-.937-.344a1.41 1.41 0 00-1.134.48 2.081 2.081 0 00-.4.71c-.066.191-.111.383-.14.502l-.002.013c-.258 1.102.495 2.102 1.507 2.339 1.012.236 2.13-.327 2.388-1.428zM51.824 33.36a3 3 0 00-2.002-3.539c-.458-.347-.957-.59-1.491-.611-.667-.026-1.165.3-1.488.68-.298.35-.478.777-.595 1.122-.119.35-.202.706-.263.967l-.004.016a3 3 0 105.843 1.365z"/>
|
||||
<path stroke="#634647" stroke-linecap="round" stroke-width="2" d="M49.784 20.368l-1.02-2.238M36.807 29.659s.569-2.435 2.36-3.168M60.877 28.325s-1.757-.41-3.193-2.325"/>
|
||||
</svg>
|
After Width: | Height: | Size: 3.2 KiB |
57
components/crisp-chat.tsx
Normal file
|
@ -0,0 +1,57 @@
|
|||
import * as React from "react";
|
||||
import Button from "./button";
|
||||
import Chat from "@/components/icons/chat.svg";
|
||||
|
||||
const crispWebsiteId = process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID;
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
$crisp?: Array<unknown>;
|
||||
CRISP_WEBSITE_ID?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export const showCrispChat = () => {
|
||||
window.$crisp?.push(["do", "chat:show"]);
|
||||
window.$crisp?.push(["do", "chat:open"]);
|
||||
};
|
||||
|
||||
export const ChatButton: React.VoidFunctionComponent<{ text?: string }> = ({
|
||||
text,
|
||||
}) => {
|
||||
return (
|
||||
<Button icon={<Chat />} onClick={showCrispChat}>
|
||||
{text}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
const CrispChat: React.VoidFunctionComponent = () => {
|
||||
React.useEffect(() => {
|
||||
if (!crispWebsiteId) {
|
||||
return;
|
||||
}
|
||||
window.$crisp = [];
|
||||
window.CRISP_WEBSITE_ID = crispWebsiteId;
|
||||
(() => {
|
||||
const d = document;
|
||||
const s = d.createElement("script");
|
||||
s.src = "https://client.crisp.chat/l.js";
|
||||
s.async = true;
|
||||
d.getElementsByTagName("body")[0].appendChild(s);
|
||||
window.$crisp.push(["safe", true]); // disable warning about other event listeners
|
||||
window.$crisp.push(["do", "chat:hide"]);
|
||||
window.$crisp.push([
|
||||
"on",
|
||||
"chat:closed",
|
||||
() => {
|
||||
window.$crisp?.push(["do", "chat:hide"]);
|
||||
},
|
||||
]);
|
||||
})();
|
||||
});
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default CrispChat;
|
42
components/date-card.tsx
Normal file
|
@ -0,0 +1,42 @@
|
|||
import clsx from "clsx";
|
||||
import * as React from "react";
|
||||
|
||||
export interface DateCardProps {
|
||||
annotation?: React.ReactNode;
|
||||
day: string;
|
||||
month: string;
|
||||
dow: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const DateCard: React.VoidFunctionComponent<DateCardProps> = ({
|
||||
annotation,
|
||||
className,
|
||||
day,
|
||||
dow,
|
||||
month,
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
"inline-block bg-white text-center border h-14 w-14 rounded-md relative shadow-md shadow-slate-100",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{annotation ? (
|
||||
<div className="absolute -top-3 -right-3">{annotation}</div>
|
||||
) : null}
|
||||
<div className="text-xs -mt-2 mb-[-1px] text-slate-400 relative">
|
||||
<span className="relative inline-block after:content-[''] after:inline-block after:absolute after:left-0 px-1 after:top-[7px] after:border-white after:-z-10 z-10 after:border-t after:w-full">
|
||||
{dow}
|
||||
</span>
|
||||
</div>
|
||||
<div className="text-red-500 text-lg -mb-1 text-center">{day}</div>
|
||||
<div className="text-gray-800 text-center text-xs uppercase font-semibold">
|
||||
{month}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DateCard;
|
233
components/discussion/discussion.tsx
Normal file
|
@ -0,0 +1,233 @@
|
|||
import { Transition } from "@headlessui/react";
|
||||
import { Comment } from "@prisma/client";
|
||||
import axios from "axios";
|
||||
import { formatRelative } from "date-fns";
|
||||
import { usePlausible } from "next-plausible";
|
||||
import * as React from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { useMutation, useQuery, useQueryClient } from "react-query";
|
||||
import { useList } from "react-use";
|
||||
import {
|
||||
createComment,
|
||||
CreateCommentPayload,
|
||||
} from "../../api-client/create-comment";
|
||||
import { requiredString } from "../../utils/form-validation";
|
||||
import Button from "../button";
|
||||
import CompactButton from "../compact-button";
|
||||
import Dropdown, { DropdownItem } from "../dropdown";
|
||||
import DotsHorizontal from "../icons/dots-horizontal.svg";
|
||||
import Trash from "../icons/trash.svg";
|
||||
import NameInput from "../name-input";
|
||||
import UserAvater from "../poll/user-avatar";
|
||||
import { useUserName } from "../user-name-context";
|
||||
|
||||
export interface DiscussionProps {
|
||||
pollId: string;
|
||||
canDelete?: boolean;
|
||||
}
|
||||
|
||||
interface CommentForm {
|
||||
authorName: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
const Comments: React.VoidFunctionComponent<{
|
||||
comments: {
|
||||
id: string;
|
||||
authorName: string;
|
||||
content: string;
|
||||
createdAt: string;
|
||||
}[];
|
||||
deletedComments: string[];
|
||||
onDelete: (commentId: string) => void;
|
||||
canDelete?: boolean;
|
||||
}> = ({ comments, deletedComments, onDelete, canDelete }) => {
|
||||
return (
|
||||
<div className="bg-slate-50 p-4 space-y-3 border-b">
|
||||
{comments.map((comment, i) => {
|
||||
return (
|
||||
<div className="flex" key={i}>
|
||||
<Transition
|
||||
show={!deletedComments.includes(comment.id)}
|
||||
as="div"
|
||||
enter="transition transform duration-300"
|
||||
enterFrom="opacity-0 translate-y-4"
|
||||
enterTo="opacity-100 translate-y-0"
|
||||
leave="transition transform duration-100"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
className="bg-white border rounded-xl px-3 py-2 shadow-sm w-fit"
|
||||
>
|
||||
<div className="flex space-x-2 items-center">
|
||||
<UserAvater name={comment.authorName} />
|
||||
<div className="mb-1">
|
||||
<span className="mr-1">{comment.authorName}</span>
|
||||
<span className="mr-1 text-slate-400">•</span>
|
||||
<span className="text-sm text-slate-500">
|
||||
{formatRelative(new Date(comment.createdAt), Date.now())}
|
||||
</span>
|
||||
</div>
|
||||
{canDelete ? (
|
||||
<Dropdown
|
||||
placement="bottom-start"
|
||||
trigger={<CompactButton icon={DotsHorizontal} />}
|
||||
>
|
||||
<DropdownItem
|
||||
icon={Trash}
|
||||
label="Delete comment"
|
||||
onClick={() => {
|
||||
onDelete(comment.id);
|
||||
}}
|
||||
/>
|
||||
</Dropdown>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="w-fit whitespace-pre-wrap">{comment.content}</div>
|
||||
</Transition>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const Discussion: React.VoidFunctionComponent<DiscussionProps> = ({
|
||||
pollId,
|
||||
canDelete,
|
||||
}) => {
|
||||
const getCommentsQueryKey = ["poll", pollId, "comments"];
|
||||
const [userName, setUserName] = useUserName();
|
||||
const [deletedComments, { push }] = useList<string>([]);
|
||||
const queryClient = useQueryClient();
|
||||
const { data: comments } = useQuery(
|
||||
getCommentsQueryKey,
|
||||
async () => {
|
||||
const res = await axios.get<{
|
||||
comments: Array<Omit<Comment, "createdAt"> & { createdAt: string }>;
|
||||
}>(`/api/poll/${pollId}/comments`);
|
||||
return res.data.comments;
|
||||
},
|
||||
{
|
||||
refetchInterval: 10000, // refetch every 10 seconds
|
||||
},
|
||||
);
|
||||
|
||||
const plausible = usePlausible();
|
||||
|
||||
const { mutate: createCommentMutation } = useMutation(
|
||||
(payload: CreateCommentPayload) => {
|
||||
// post comment
|
||||
return createComment(payload);
|
||||
},
|
||||
{
|
||||
onSuccess: (newComment) => {
|
||||
queryClient.setQueryData(getCommentsQueryKey, (comments) => {
|
||||
if (Array.isArray(comments)) {
|
||||
return [...comments, newComment];
|
||||
}
|
||||
return [newComment];
|
||||
});
|
||||
plausible("Created comment");
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const { mutate: deleteCommentMutation } = useMutation(
|
||||
async (payload: { pollId: string; commentId: string }) => {
|
||||
await axios.delete(`/api/poll/${pollId}/comments/${payload.commentId}`);
|
||||
},
|
||||
{
|
||||
onMutate: ({ commentId }) => {
|
||||
push(commentId);
|
||||
plausible("Deleted comment");
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(getCommentsQueryKey);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const { register, setValue, control, handleSubmit, formState } =
|
||||
useForm<CommentForm>({
|
||||
defaultValues: {
|
||||
authorName: userName,
|
||||
content: "",
|
||||
},
|
||||
});
|
||||
|
||||
React.useEffect(() => {
|
||||
setValue("authorName", userName);
|
||||
}, [setValue, userName]);
|
||||
|
||||
const handleDelete = React.useCallback(
|
||||
(commentId: string) => {
|
||||
deleteCommentMutation({ pollId, commentId });
|
||||
},
|
||||
[deleteCommentMutation, pollId],
|
||||
);
|
||||
|
||||
if (!comments) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="border-t border-b md:border md:rounded-lg overflow-hidden shadow-sm">
|
||||
<div className="px-4 py-2 bg-white border-b">
|
||||
<div className="font-medium">Comments</div>
|
||||
</div>
|
||||
{comments.length ? (
|
||||
<Comments
|
||||
comments={comments}
|
||||
canDelete={canDelete}
|
||||
onDelete={handleDelete}
|
||||
deletedComments={deletedComments}
|
||||
/>
|
||||
) : null}
|
||||
<form
|
||||
className="bg-white p-4"
|
||||
onSubmit={handleSubmit((data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
createCommentMutation(
|
||||
{
|
||||
...data,
|
||||
pollId,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
setUserName(data.authorName);
|
||||
setValue("content", "");
|
||||
resolve(data);
|
||||
},
|
||||
onError: reject,
|
||||
},
|
||||
);
|
||||
});
|
||||
})}
|
||||
>
|
||||
<textarea
|
||||
id="comment"
|
||||
placeholder="Add your comment…"
|
||||
className="input pl-3 pr-4 py-2 w-full"
|
||||
{...register("content", { validate: requiredString })}
|
||||
/>
|
||||
<div className="flex mt-1 space-x-3">
|
||||
<Controller
|
||||
name="authorName"
|
||||
control={control}
|
||||
rules={{ validate: requiredString }}
|
||||
render={({ field }) => <NameInput className="w-full" {...field} />}
|
||||
/>
|
||||
<Button
|
||||
htmlType="submit"
|
||||
loading={formState.isSubmitting}
|
||||
type="primary"
|
||||
>
|
||||
Send
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(Discussion);
|
1
components/discussion/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from "./discussion";
|
99
components/dropdown.tsx
Normal file
|
@ -0,0 +1,99 @@
|
|||
import { Menu } from "@headlessui/react";
|
||||
import { Placement } from "@popperjs/core";
|
||||
import clsx from "clsx";
|
||||
import * as React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { usePopper } from "react-popper";
|
||||
export interface DropdownProps {
|
||||
trigger?: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
placement?: Placement;
|
||||
}
|
||||
|
||||
const Dropdown: React.VoidFunctionComponent<DropdownProps> = ({
|
||||
children,
|
||||
className,
|
||||
trigger,
|
||||
placement,
|
||||
}) => {
|
||||
const [referenceElement, setReferenceElement] =
|
||||
React.useState<HTMLDivElement | null>(null);
|
||||
const [popperElement, setPopperElement] =
|
||||
React.useState<HTMLDivElement | null>(null);
|
||||
|
||||
const { styles, attributes } = usePopper(referenceElement, popperElement, {
|
||||
placement,
|
||||
modifiers: [
|
||||
{
|
||||
name: "offset",
|
||||
options: {
|
||||
offset: [0, 5],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const portal = document.getElementById("portal");
|
||||
return (
|
||||
<Menu>
|
||||
<Menu.Button
|
||||
ref={setReferenceElement}
|
||||
as="div"
|
||||
className={clsx("inline-block", className)}
|
||||
>
|
||||
{trigger}
|
||||
</Menu.Button>
|
||||
{portal &&
|
||||
ReactDOM.createPortal(
|
||||
<Menu.Items
|
||||
as="div"
|
||||
ref={setPopperElement}
|
||||
style={styles.popper}
|
||||
{...attributes.popper}
|
||||
className="z-30 p-1 bg-white divide-gray-100 rounded-md shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"
|
||||
>
|
||||
{children}
|
||||
</Menu.Items>,
|
||||
portal,
|
||||
)}
|
||||
</Menu>
|
||||
);
|
||||
};
|
||||
|
||||
export const DropdownItem: React.VoidFunctionComponent<{
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
label?: React.ReactNode;
|
||||
disabled?: boolean;
|
||||
onClick?: () => void;
|
||||
}> = ({ icon: Icon, label, onClick, disabled }) => {
|
||||
return (
|
||||
<Menu.Item disabled={disabled}>
|
||||
{({ active }) => (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className={clsx(
|
||||
"group flex rounded items-center w-full py-2 pl-2 pr-4",
|
||||
{
|
||||
"bg-indigo-500 text-white": active,
|
||||
"text-gray-700": !active,
|
||||
"opacity-50": disabled,
|
||||
},
|
||||
)}
|
||||
>
|
||||
{Icon && (
|
||||
<Icon
|
||||
className={clsx("w-5 h-5 mr-2", {
|
||||
"text-white": active,
|
||||
"text-indigo-500": !disabled,
|
||||
})}
|
||||
/>
|
||||
)}
|
||||
{label}
|
||||
</button>
|
||||
)}
|
||||
</Menu.Item>
|
||||
);
|
||||
};
|
||||
|
||||
export default Dropdown;
|
50
components/error-page.tsx
Normal file
|
@ -0,0 +1,50 @@
|
|||
import Head from "next/head";
|
||||
import Link from "next/link";
|
||||
import * as React from "react";
|
||||
import StandardLayout from "./standard-layout";
|
||||
import Button from "@/components/button";
|
||||
import Chat from "@/components/icons/chat.svg";
|
||||
import EmojiSad from "@/components/icons/emoji-sad.svg";
|
||||
import { showCrispChat } from "./crisp-chat";
|
||||
|
||||
export interface ComponentProps {
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
title: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
const ErrorPage: React.VoidFunctionComponent<ComponentProps> = ({
|
||||
icon: Icon = EmojiSad,
|
||||
title,
|
||||
description,
|
||||
}) => {
|
||||
return (
|
||||
<StandardLayout>
|
||||
<div className="h-full bg-gray-50 px-4 py-8 flex items-center justify-center lg:w-[1024px] max-w-full">
|
||||
<Head>
|
||||
<title>{title}</title>
|
||||
<meta name="robots" content="noindex,nofollow" />
|
||||
</Head>
|
||||
<div className="flex items-start">
|
||||
<div className="text-center">
|
||||
<Icon className="w-24 inline-block mb-4 text-slate-400" />
|
||||
<div className="text-3xl font-bold uppercase text-indigo-500 ">
|
||||
{title}
|
||||
</div>
|
||||
<p>{description}</p>
|
||||
<div className="flex space-x-3 justify-center">
|
||||
<Link href="/" passHref={true}>
|
||||
<a className="btn-default">Go to home</a>
|
||||
</Link>
|
||||
<Button icon={<Chat />} onClick={showCrispChat}>
|
||||
Start chat
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</StandardLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export default ErrorPage;
|
7
components/forms/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
export type { PollDetailsData } from "./poll-details-form";
|
||||
export { PollDetailsForm } from "./poll-details-form";
|
||||
export type { PollOptionsData } from "./poll-options-form/poll-options-form";
|
||||
export { default as PollOptionsForm } from "./poll-options-form/poll-options-form";
|
||||
export * from "./types";
|
||||
export type { UserDetailsData } from "./user-details-form";
|
||||
export { UserDetailsForm } from "./user-details-form";
|
76
components/forms/poll-details-form.tsx
Normal file
|
@ -0,0 +1,76 @@
|
|||
import clsx from "clsx";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import * as React from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { requiredString } from "../../utils/form-validation";
|
||||
import { PollFormProps } from "./types";
|
||||
|
||||
export interface PollDetailsData {
|
||||
title: string;
|
||||
location: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export const PollDetailsForm: React.VoidFunctionComponent<
|
||||
PollFormProps<PollDetailsData>
|
||||
> = ({ name, defaultValues, onSubmit, onChange, className }) => {
|
||||
const { t } = useTranslation("app");
|
||||
const {
|
||||
handleSubmit,
|
||||
register,
|
||||
watch,
|
||||
formState: { errors },
|
||||
} = useForm<PollDetailsData>({ defaultValues });
|
||||
|
||||
React.useEffect(() => {
|
||||
if (onChange) {
|
||||
const subscription = watch(onChange);
|
||||
return () => {
|
||||
subscription.unsubscribe();
|
||||
};
|
||||
}
|
||||
}, [onChange, watch]);
|
||||
|
||||
return (
|
||||
<form
|
||||
id={name}
|
||||
className={clsx("max-w-full", className)}
|
||||
style={{ width: 500 }}
|
||||
onSubmit={handleSubmit(onSubmit)}
|
||||
>
|
||||
<div className="formField">
|
||||
<label htmlFor="title">{t("title")}</label>
|
||||
<input
|
||||
type="text"
|
||||
id="title"
|
||||
className={clsx("input w-full", {
|
||||
"input-error": errors.title,
|
||||
})}
|
||||
placeholder={t("titlePlaceholder")}
|
||||
{...register("title", { validate: requiredString })}
|
||||
/>
|
||||
</div>
|
||||
<div className="formField">
|
||||
<label htmlFor="location">{t("location")}</label>
|
||||
<input
|
||||
type="text"
|
||||
id="location"
|
||||
className="input w-full"
|
||||
placeholder={t("locationPlaceholder")}
|
||||
{...register("location")}
|
||||
/>
|
||||
</div>
|
||||
<div className="formField">
|
||||
<label htmlFor="description">{t("description")}</label>
|
||||
<textarea
|
||||
id="description"
|
||||
className="input w-full"
|
||||
placeholder={t("descriptionPlaceholder")}
|
||||
rows={5}
|
||||
{...register("description")}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
|
@ -0,0 +1,39 @@
|
|||
import * as React from "react";
|
||||
|
||||
import ChevronLeft from "../../icons/chevron-left.svg";
|
||||
import ChevronRight from "../../icons/chevron-right.svg";
|
||||
|
||||
export interface DateNavigationToolbarProps {
|
||||
year: number;
|
||||
label: string;
|
||||
onPrevious: () => void;
|
||||
onNext: () => void;
|
||||
onToday: () => void;
|
||||
}
|
||||
|
||||
const DateNavigationToolbar: React.VoidFunctionComponent<DateNavigationToolbarProps> =
|
||||
({ year, label, onPrevious, onToday, onNext }) => {
|
||||
return (
|
||||
<div className="flex border-b items-center w-full px-4 h-14 shrink-0">
|
||||
<div className="grow">
|
||||
<span className="text-sm font-bold text-gray-400 mr-2">{year}</span>
|
||||
<span className="text-lg font-bold text-gray-700">{label}</span>
|
||||
</div>
|
||||
<div className="flex space-x-2 items-center">
|
||||
<div className="segment-button">
|
||||
<button type="button" onClick={onPrevious}>
|
||||
<ChevronLeft className="h-5" />
|
||||
</button>
|
||||
<button type="button" onClick={onToday}>
|
||||
Today
|
||||
</button>
|
||||
<button type="button" onClick={onNext}>
|
||||
<ChevronRight className="h-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DateNavigationToolbar;
|
2
components/forms/poll-options-form/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export { default } from "./poll-options-form";
|
||||
export * from "./types";
|
|
@ -0,0 +1 @@
|
|||
export { default } from "./month-calendar";
|
|
@ -0,0 +1,426 @@
|
|||
import clsx from "clsx";
|
||||
import differenceInMinutes from "date-fns/differenceInMinutes";
|
||||
import { addMinutes, setHours } from "date-fns/esm";
|
||||
import isSameDay from "date-fns/isSameDay";
|
||||
import { usePlausible } from "next-plausible";
|
||||
import * as React from "react";
|
||||
import { DateTimeOption } from "..";
|
||||
import {
|
||||
expectTimeOption,
|
||||
getDateProps,
|
||||
removeAllOptionsForDay,
|
||||
} from "../../../../utils/date-time-utils";
|
||||
import Button from "../../../button";
|
||||
import CompactButton from "../../../compact-button";
|
||||
import DateCard from "../../../date-card";
|
||||
import Dropdown, { DropdownItem } from "../../../dropdown";
|
||||
import { useHeadlessDatePicker } from "../../../headless-date-picker";
|
||||
import Calendar from "../../../icons/calendar.svg";
|
||||
import ChevronLeft from "../../../icons/chevron-left.svg";
|
||||
import ChevronRight from "../../../icons/chevron-right.svg";
|
||||
import DotsHorizontal from "../../../icons/dots-horizontal.svg";
|
||||
import Magic from "../../../icons/magic.svg";
|
||||
import PlusSm from "../../../icons/plus-sm.svg";
|
||||
import Trash from "../../../icons/trash.svg";
|
||||
import X from "../../../icons/x.svg";
|
||||
import Switch from "../../../switch";
|
||||
import { DateTimePickerProps } from "../types";
|
||||
import { formatDateWithoutTime, formatDateWithoutTz } from "../utils";
|
||||
import TimePicker from "./time-picker";
|
||||
|
||||
const MonthCalendar: React.VoidFunctionComponent<DateTimePickerProps> = ({
|
||||
options,
|
||||
onNavigate,
|
||||
date,
|
||||
onChange,
|
||||
duration,
|
||||
onChangeDuration,
|
||||
}) => {
|
||||
const isTimedEvent = options.some((option) => option.type === "timeSlot");
|
||||
|
||||
const plausible = usePlausible();
|
||||
|
||||
const optionsByDay = React.useMemo(() => {
|
||||
const res: Record<
|
||||
string,
|
||||
[
|
||||
{
|
||||
option: DateTimeOption;
|
||||
index: number;
|
||||
},
|
||||
]
|
||||
> = {};
|
||||
|
||||
options.forEach((option, index) => {
|
||||
const dateString =
|
||||
option.type === "date"
|
||||
? option.date
|
||||
: option.start.substring(0, option.start.indexOf("T"));
|
||||
|
||||
if (res[dateString]) {
|
||||
res[dateString].push({ option, index });
|
||||
} else {
|
||||
res[dateString] = [{ option, index }];
|
||||
}
|
||||
});
|
||||
|
||||
return res;
|
||||
}, [options]);
|
||||
|
||||
const datepickerSelection = React.useMemo(() => {
|
||||
return Object.keys(optionsByDay).map(
|
||||
(dateString) => new Date(dateString + "T12:00:00"),
|
||||
);
|
||||
}, [optionsByDay]);
|
||||
|
||||
const datepicker = useHeadlessDatePicker({
|
||||
selection: datepickerSelection,
|
||||
onNavigationChange: onNavigate,
|
||||
date,
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="lg:flex overflow-hidden">
|
||||
<div className="p-4 border-b lg:border-r lg:border-b-0 shrink-0">
|
||||
<div>
|
||||
<div className="w-full flex flex-col">
|
||||
<div className="flex space-x-4 items-center justify-center mb-3">
|
||||
<Button
|
||||
icon={<ChevronLeft />}
|
||||
title="Previous month"
|
||||
onClick={datepicker.prev}
|
||||
/>
|
||||
<div className="grow text-center font-medium text-lg">
|
||||
{datepicker.label}
|
||||
</div>
|
||||
<Button
|
||||
title="Next month"
|
||||
icon={<ChevronRight />}
|
||||
onClick={datepicker.next}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-7">
|
||||
{datepicker.daysOfWeek.map((dayOfWeek) => {
|
||||
return (
|
||||
<div
|
||||
key={dayOfWeek}
|
||||
className="flex items-center justify-center pb-2 text-slate-400 text-sm font-medium"
|
||||
>
|
||||
{dayOfWeek.substring(0, 2)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className="grid grid-cols-7 grow border shadow-sm rounded-lg overflow-hidden bg-white">
|
||||
{datepicker.days.map((day, i) => {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
key={i}
|
||||
onClick={() => {
|
||||
if (
|
||||
datepicker.selection.some((selectedDate) =>
|
||||
isSameDay(selectedDate, day.date),
|
||||
)
|
||||
) {
|
||||
onChange(removeAllOptionsForDay(options, day.date));
|
||||
} else {
|
||||
const selectedDate = setHours(day.date, 12);
|
||||
const newOption: DateTimeOption = !isTimedEvent
|
||||
? {
|
||||
type: "date",
|
||||
date: formatDateWithoutTime(selectedDate),
|
||||
}
|
||||
: {
|
||||
type: "timeSlot",
|
||||
start: formatDateWithoutTz(selectedDate),
|
||||
end: formatDateWithoutTz(
|
||||
addMinutes(selectedDate, duration),
|
||||
),
|
||||
};
|
||||
|
||||
onChange([...options, newOption]);
|
||||
onNavigate(selectedDate);
|
||||
}
|
||||
if (day.outOfMonth) {
|
||||
if (i < 6) {
|
||||
datepicker.prev();
|
||||
} else {
|
||||
datepicker.next();
|
||||
}
|
||||
}
|
||||
}}
|
||||
className={clsx(
|
||||
"flex items-center relative lg:w-14 justify-center focus:ring-0 focus:ring-offset-0 hover:bg-slate-50 px-4 py-3 text-sm active:bg-slate-100",
|
||||
{
|
||||
"text-slate-400 bg-slate-50": day.outOfMonth,
|
||||
"font-bold text-indigo-500": day.today,
|
||||
"border-r": (i + 1) % 7 !== 0,
|
||||
"border-b": i < datepicker.days.length - 7,
|
||||
"font-normal after:content-[''] after:animate-popIn after:absolute after:w-8 after:h-8 after:rounded-full after:bg-green-500 after:-z-0 text-white":
|
||||
day.selected,
|
||||
},
|
||||
)}
|
||||
>
|
||||
<span className="z-10">{day.day}</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<Button className="mt-3" onClick={datepicker.today}>
|
||||
Today
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grow flex flex-col">
|
||||
<div
|
||||
className={clsx("border-b", {
|
||||
hidden: datepicker.selection.length === 0,
|
||||
})}
|
||||
>
|
||||
<div className="p-4 flex space-x-3 items-center">
|
||||
<div className="grow">
|
||||
<div className="font-medium">Specify times</div>
|
||||
<div className="text-sm text-slate-400">
|
||||
Include start and end times for each option
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
checked={isTimedEvent}
|
||||
onChange={(checked) => {
|
||||
if (checked) {
|
||||
// convert dates to time slots
|
||||
onChange(
|
||||
options.map((option) => {
|
||||
if (option.type === "timeSlot") {
|
||||
throw new Error(
|
||||
"Expected option to be a date but received timeSlot",
|
||||
);
|
||||
}
|
||||
const startDate = new Date(`${option.date}T12:00:00`);
|
||||
const endDate = addMinutes(startDate, duration);
|
||||
return {
|
||||
type: "timeSlot",
|
||||
start: formatDateWithoutTz(startDate),
|
||||
end: formatDateWithoutTz(endDate),
|
||||
};
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
onChange(
|
||||
datepicker.selection.map((date) => ({
|
||||
type: "date",
|
||||
date: formatDateWithoutTime(date),
|
||||
})),
|
||||
);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grow px-4">
|
||||
{isTimedEvent ? (
|
||||
<div className="divide-y">
|
||||
{Object.keys(optionsByDay)
|
||||
.sort((a, b) => (a > b ? 1 : -1))
|
||||
.map((dateString) => {
|
||||
const optionsForDay = optionsByDay[dateString];
|
||||
return (
|
||||
<div
|
||||
key={dateString}
|
||||
className="py-4 space-y-3 xs:space-y-0 xs:space-x-4 xs:flex"
|
||||
>
|
||||
<div>
|
||||
<DateCard
|
||||
{...getDateProps(new Date(dateString + "T12:00:00"))}
|
||||
/>
|
||||
</div>
|
||||
<div className="grow space-y-3">
|
||||
{optionsForDay.map(({ option, index }) => {
|
||||
if (option.type === "date") {
|
||||
throw new Error("Expected timeSlot but got date");
|
||||
}
|
||||
const startDate = new Date(option.start);
|
||||
return (
|
||||
<div
|
||||
key={index}
|
||||
className="flex space-x-3 items-center"
|
||||
>
|
||||
<TimePicker
|
||||
value={startDate}
|
||||
onChange={(newStart) => {
|
||||
const newEnd = addMinutes(newStart, duration);
|
||||
// replace enter with updated start time
|
||||
onChange([
|
||||
...options.slice(0, index),
|
||||
{
|
||||
...option,
|
||||
start: formatDateWithoutTz(newStart),
|
||||
end: formatDateWithoutTz(newEnd),
|
||||
},
|
||||
...options.slice(index + 1),
|
||||
]);
|
||||
onNavigate(newStart);
|
||||
onChangeDuration(
|
||||
differenceInMinutes(newEnd, newStart),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<TimePicker
|
||||
value={new Date(option.end)}
|
||||
startFrom={addMinutes(startDate, 15)}
|
||||
onChange={(newEnd) => {
|
||||
onChange([
|
||||
...options.slice(0, index),
|
||||
{
|
||||
...option,
|
||||
end: formatDateWithoutTz(newEnd),
|
||||
},
|
||||
...options.slice(index + 1),
|
||||
]);
|
||||
onNavigate(newEnd);
|
||||
onChangeDuration(
|
||||
differenceInMinutes(newEnd, startDate),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<CompactButton
|
||||
icon={X}
|
||||
onClick={() => {
|
||||
onChange([
|
||||
...options.slice(0, index),
|
||||
...options.slice(index + 1),
|
||||
]);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<div className="flex space-x-3 items-center">
|
||||
<Button
|
||||
icon={<PlusSm />}
|
||||
onClick={() => {
|
||||
const lastOption = expectTimeOption(
|
||||
optionsForDay[optionsForDay.length - 1].option,
|
||||
);
|
||||
const startTime = lastOption.start;
|
||||
|
||||
onChange([
|
||||
...options,
|
||||
{
|
||||
type: "timeSlot",
|
||||
start: startTime,
|
||||
end: formatDateWithoutTz(
|
||||
addMinutes(new Date(startTime), duration),
|
||||
),
|
||||
},
|
||||
]);
|
||||
}}
|
||||
>
|
||||
Add time option
|
||||
</Button>
|
||||
<Dropdown
|
||||
trigger={<CompactButton icon={DotsHorizontal} />}
|
||||
placement="bottom-start"
|
||||
>
|
||||
<DropdownItem
|
||||
icon={Magic}
|
||||
disabled={datepicker.selection.length < 2}
|
||||
label="Apply to all dates"
|
||||
onClick={() => {
|
||||
plausible("Applied options to all dates");
|
||||
const times = optionsForDay.map(
|
||||
({ option }) => {
|
||||
if (option.type === "date") {
|
||||
throw new Error(
|
||||
"Expected timeSlot but got date",
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
startTime: option.start.substring(
|
||||
option.start.indexOf("T"),
|
||||
),
|
||||
endTime: option.end.substring(
|
||||
option.end.indexOf("T"),
|
||||
),
|
||||
};
|
||||
},
|
||||
);
|
||||
const newOptions: DateTimeOption[] = [];
|
||||
Object.keys(optionsByDay).forEach(
|
||||
(dateString) => {
|
||||
times.forEach((time) => {
|
||||
newOptions.push({
|
||||
type: "timeSlot",
|
||||
start: dateString + time.startTime,
|
||||
end: dateString + time.endTime,
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
onChange(newOptions);
|
||||
}}
|
||||
/>
|
||||
<DropdownItem
|
||||
label="Delete date"
|
||||
icon={Trash}
|
||||
onClick={() => {
|
||||
onChange(
|
||||
removeAllOptionsForDay(
|
||||
options,
|
||||
new Date(dateString),
|
||||
),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : datepicker.selection.length ? (
|
||||
<div className="grid grid-cols-[repeat(auto-fill,60px)] gap-5 py-4">
|
||||
{datepicker.selection
|
||||
.sort((a, b) => a.getTime() - b.getTime())
|
||||
.map((selectedDate, i) => {
|
||||
return (
|
||||
<DateCard
|
||||
key={i}
|
||||
{...getDateProps(selectedDate)}
|
||||
annotation={
|
||||
<CompactButton
|
||||
icon={X}
|
||||
onClick={() => {
|
||||
// TODO (Luke Vella) [2022-03-19]: Find cleaner way to manage this state
|
||||
// Quite tedious right now to remove a single element
|
||||
onChange(
|
||||
removeAllOptionsForDay(options, selectedDate),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex h-full items-center justify-center py-12">
|
||||
<div className="text-center font-medium text-gray-400">
|
||||
<Calendar className="inline-block h-12 w-12 mb-2" />
|
||||
<div>No dates selected</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MonthCalendar;
|
|
@ -0,0 +1,107 @@
|
|||
import { Combobox } from "@headlessui/react";
|
||||
import clsx from "clsx";
|
||||
import { addMinutes, format, isSameDay, setHours, setMinutes } from "date-fns";
|
||||
import * as React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { usePopper } from "react-popper";
|
||||
|
||||
import ChevronDown from "../../../icons/chevron-down.svg";
|
||||
import { styleMenuItem } from "../../../menu-styles";
|
||||
|
||||
export interface TimePickerProps {
|
||||
value: Date;
|
||||
startFrom?: Date;
|
||||
className?: string;
|
||||
onChange?: (value: Date) => void;
|
||||
}
|
||||
|
||||
const TimePicker: React.VoidFunctionComponent<TimePickerProps> = ({
|
||||
value,
|
||||
onChange,
|
||||
className,
|
||||
startFrom = setMinutes(setHours(value, 0), 0),
|
||||
}) => {
|
||||
const [referenceElement, setReferenceElement] =
|
||||
React.useState<HTMLDivElement | null>(null);
|
||||
const [popperElement, setPopperElement] =
|
||||
React.useState<HTMLUListElement | null>(null);
|
||||
|
||||
const { styles, attributes } = usePopper(referenceElement, popperElement, {
|
||||
modifiers: [
|
||||
{
|
||||
name: "offset",
|
||||
options: {
|
||||
offset: [0, 5],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const [query, setQuery] = React.useState("");
|
||||
const options: React.ReactNode[] = [];
|
||||
for (let i = 0; i < 96; i++) {
|
||||
const optionValue = addMinutes(startFrom, i * 15);
|
||||
if (!isSameDay(value, optionValue)) {
|
||||
// we only support event that start and end on the same day for now
|
||||
// because react-big-calendar does not support events that span days
|
||||
break;
|
||||
}
|
||||
if (query && !format(optionValue, "hhmma").includes(query)) {
|
||||
continue;
|
||||
}
|
||||
options.push(
|
||||
<Combobox.Option
|
||||
key={i}
|
||||
className={styleMenuItem}
|
||||
value={optionValue.toISOString()}
|
||||
>
|
||||
{format(optionValue, "p")}
|
||||
</Combobox.Option>,
|
||||
);
|
||||
}
|
||||
|
||||
const portal = document.getElementById("portal");
|
||||
|
||||
return (
|
||||
<Combobox
|
||||
value={value.toISOString()}
|
||||
onChange={(newValue) => {
|
||||
setQuery("");
|
||||
onChange?.(new Date(newValue));
|
||||
}}
|
||||
>
|
||||
<div ref={setReferenceElement} className={clsx("relative", className)}>
|
||||
{/* Remove generic params once Combobox.Input can infer the types */}
|
||||
<Combobox.Input<"input">
|
||||
className="input w-28 pr-8"
|
||||
displayValue={() => ""}
|
||||
onChange={(e) => {
|
||||
setQuery(e.target.value.toUpperCase().replace(/[\:\s]/g, ""));
|
||||
}}
|
||||
/>
|
||||
<Combobox.Button className="absolute inset-0 flex items-center cursor-default px-2 h-9 text-left">
|
||||
<span className="grow truncate">
|
||||
{!query ? format(value, "p") : null}
|
||||
</span>
|
||||
<span className="flex pointer-events-none">
|
||||
<ChevronDown className="w-5 h-5" />
|
||||
</span>
|
||||
</Combobox.Button>
|
||||
{portal &&
|
||||
ReactDOM.createPortal(
|
||||
<Combobox.Options
|
||||
style={styles.popper}
|
||||
{...attributes.popper}
|
||||
ref={setPopperElement}
|
||||
className="z-50 w-32 py-1 overflow-auto bg-white rounded-md shadow-lg max-h-72 ring-1 ring-black ring-opacity-5 focus:outline-none"
|
||||
>
|
||||
{options}
|
||||
</Combobox.Options>,
|
||||
portal,
|
||||
)}
|
||||
</div>
|
||||
</Combobox>
|
||||
);
|
||||
};
|
||||
|
||||
export default TimePicker;
|
233
components/forms/poll-options-form/poll-options-form.tsx
Normal file
|
@ -0,0 +1,233 @@
|
|||
import clsx from "clsx";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import * as React from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
|
||||
import { getBrowserTimeZone } from "../../../utils/date-time-utils";
|
||||
import FullPageLoader from "../../full-page-loader";
|
||||
import Calendar from "../../icons/calendar.svg";
|
||||
import Table from "../../icons/table.svg";
|
||||
import { useModal } from "../../modal";
|
||||
import TimeZonePicker from "../../time-zone-picker";
|
||||
import { PollFormProps } from "../types";
|
||||
import { DateTimeOption } from "./types";
|
||||
|
||||
const WeekCalendar = React.lazy(() => import("./week-calendar"));
|
||||
const MonthCalendar = React.lazy(() => import("./month-calendar"));
|
||||
|
||||
export type PollOptionsData = {
|
||||
navigationDate: string; // used to navigate to the right part of the calendar
|
||||
duration: number; // duration of the event in minutes
|
||||
timeZone: string;
|
||||
view: string;
|
||||
options: DateTimeOption[];
|
||||
};
|
||||
|
||||
const PollOptionsForm: React.VoidFunctionComponent<
|
||||
PollFormProps<PollOptionsData> & { title?: string }
|
||||
> = ({ name, defaultValues, onSubmit, onChange, title, className }) => {
|
||||
const { t } = useTranslation("app");
|
||||
const { control, handleSubmit, watch, setValue, formState } =
|
||||
useForm<PollOptionsData>({
|
||||
defaultValues: {
|
||||
options: [],
|
||||
duration: 30,
|
||||
timeZone: "",
|
||||
navigationDate: new Date().toISOString(),
|
||||
...defaultValues,
|
||||
},
|
||||
resolver: (values) => {
|
||||
return {
|
||||
values,
|
||||
errors:
|
||||
values.options.length === 0
|
||||
? {
|
||||
options: true,
|
||||
}
|
||||
: {},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const views = React.useMemo(() => {
|
||||
const res = [
|
||||
{
|
||||
label: "Month view",
|
||||
value: "month",
|
||||
Component: MonthCalendar,
|
||||
},
|
||||
{
|
||||
label: "Week view",
|
||||
value: "week",
|
||||
Component: WeekCalendar,
|
||||
},
|
||||
];
|
||||
return res;
|
||||
}, []);
|
||||
|
||||
const watchView = watch("view");
|
||||
|
||||
const selectedView = React.useMemo(
|
||||
() => views.find((view) => view.value === watchView) ?? views[0],
|
||||
[views, watchView],
|
||||
);
|
||||
|
||||
const watchOptions = watch("options");
|
||||
const watchDuration = watch("duration");
|
||||
const watchTimeZone = watch("timeZone");
|
||||
|
||||
const datesOnly = watchOptions.every((option) => option.type === "date");
|
||||
|
||||
const [dateOrTimeRangeModal, openDateOrTimeRangeModal] = useModal({
|
||||
title: "Wait a minute… 🤔",
|
||||
description:
|
||||
"You can't have both time and date options in the same poll. Which would you like to keep?",
|
||||
okText: "Keep time options",
|
||||
onOk: () => {
|
||||
setValue(
|
||||
"options",
|
||||
watchOptions.filter((option) => option.type === "timeSlot"),
|
||||
);
|
||||
if (!watchTimeZone) {
|
||||
setValue("timeZone", getBrowserTimeZone());
|
||||
}
|
||||
},
|
||||
cancelText: "Keep date options",
|
||||
onCancel: () => {
|
||||
setValue(
|
||||
"options",
|
||||
watchOptions.filter((option) => option.type === "date"),
|
||||
);
|
||||
setValue("timeZone", "");
|
||||
},
|
||||
});
|
||||
|
||||
React.useEffect(() => {
|
||||
if (onChange) {
|
||||
const subscription = watch(({ options = [], ...rest }) => {
|
||||
// Watch returns a deep partial here which is not really accurate and messes up
|
||||
// the types a bit. Repackaging it to keep the types sane.
|
||||
onChange({ options: options as DateTimeOption[], ...rest });
|
||||
});
|
||||
return () => {
|
||||
subscription.unsubscribe();
|
||||
};
|
||||
}
|
||||
}, [watch, onChange]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (watchOptions.length > 1) {
|
||||
const optionType = watchOptions[0].type;
|
||||
// all options needs to be the same type
|
||||
if (watchOptions.some((option) => option.type !== optionType)) {
|
||||
openDateOrTimeRangeModal();
|
||||
}
|
||||
}
|
||||
}, [watchOptions, openDateOrTimeRangeModal]);
|
||||
|
||||
const watchNavigationDate = watch("navigationDate");
|
||||
const navigationDate = new Date(watchNavigationDate);
|
||||
|
||||
const [calendarHelpModal, openHelpModal] = useModal({
|
||||
overlayClosable: true,
|
||||
title: "Forget something?",
|
||||
description: t("calendarHelp"),
|
||||
okText: t("ok"),
|
||||
});
|
||||
|
||||
return (
|
||||
<form
|
||||
id={name}
|
||||
className={clsx("max-w-full", className)}
|
||||
style={{ width: 1024 }}
|
||||
onSubmit={handleSubmit(onSubmit, openHelpModal)}
|
||||
>
|
||||
{calendarHelpModal}
|
||||
{dateOrTimeRangeModal}
|
||||
<div className="py-3 space-y-2 lg:space-y-0 border-b w-full lg:space-x-2 bg-slate-50 items-center lg:flex px-4">
|
||||
<div className="grow">
|
||||
<Controller
|
||||
control={control}
|
||||
name="timeZone"
|
||||
render={({ field }) => (
|
||||
<TimeZonePicker
|
||||
value={field.value}
|
||||
onBlur={field.onBlur}
|
||||
onChange={(timeZone) => {
|
||||
setValue("timeZone", timeZone, { shouldTouch: true });
|
||||
}}
|
||||
disabled={datesOnly}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex space-x-3">
|
||||
<div className="segment-button w-full">
|
||||
<button
|
||||
className={clsx({
|
||||
"segment-button-active": selectedView.value === "month",
|
||||
})}
|
||||
onClick={() => {
|
||||
setValue("view", "month");
|
||||
}}
|
||||
type="button"
|
||||
>
|
||||
<Calendar className="h-5 w-5 mr-2" /> Month view
|
||||
</button>
|
||||
<button
|
||||
className={clsx({
|
||||
"segment-button-active": selectedView.value === "week",
|
||||
})}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setValue("view", "week");
|
||||
}}
|
||||
>
|
||||
<Table className="h-5 w-5 mr-2" /> Week view
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full relative">
|
||||
<React.Suspense
|
||||
fallback={
|
||||
<FullPageLoader className="h-[400px]">Loading…</FullPageLoader>
|
||||
}
|
||||
>
|
||||
<selectedView.Component
|
||||
title={title}
|
||||
options={watchOptions}
|
||||
date={navigationDate}
|
||||
onNavigate={(date) => {
|
||||
setValue("navigationDate", date.toISOString());
|
||||
}}
|
||||
onChange={(options) => {
|
||||
setValue("options", options);
|
||||
if (
|
||||
options.length === 0 ||
|
||||
options.every((option) => option.type === "date")
|
||||
) {
|
||||
// unset the timeZone if we only have date option
|
||||
setValue("timeZone", "");
|
||||
}
|
||||
if (
|
||||
options.length > 0 &&
|
||||
!formState.touchedFields.timeZone &&
|
||||
options.every((option) => option.type === "timeSlot")
|
||||
) {
|
||||
// set timeZone if we are adding time ranges and we haven't touched the timeZone field
|
||||
setValue("timeZone", getBrowserTimeZone());
|
||||
}
|
||||
}}
|
||||
duration={watchDuration}
|
||||
onChangeDuration={(duration) => {
|
||||
setValue("duration", duration);
|
||||
}}
|
||||
/>
|
||||
</React.Suspense>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(PollOptionsForm);
|
23
components/forms/poll-options-form/types.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
export type DateOption = {
|
||||
type: "date";
|
||||
date: string;
|
||||
};
|
||||
|
||||
export type TimeOption = {
|
||||
type: "timeSlot";
|
||||
start: string;
|
||||
end: string;
|
||||
};
|
||||
|
||||
export type DateTimeOption = DateOption | TimeOption;
|
||||
|
||||
export interface DateTimePickerProps {
|
||||
title?: string;
|
||||
options: DateTimeOption[];
|
||||
date: Date;
|
||||
onNavigate: (date: Date) => void;
|
||||
onChange: (options: DateTimeOption[]) => void;
|
||||
duration: number;
|
||||
onChangeDuration: (duration: number) => void;
|
||||
scrollToTime?: Date;
|
||||
}
|
9
components/forms/poll-options-form/utils.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { format } from "date-fns";
|
||||
|
||||
export const formatDateWithoutTz = (date: Date): string => {
|
||||
return format(date, "yyyy-MM-dd'T'HH:mm:ss");
|
||||
};
|
||||
|
||||
export const formatDateWithoutTime = (date: Date): string => {
|
||||
return format(date, "yyyy-MM-dd");
|
||||
};
|
193
components/forms/poll-options-form/week-calendar.tsx
Normal file
|
@ -0,0 +1,193 @@
|
|||
import clsx from "clsx";
|
||||
import {
|
||||
addMinutes,
|
||||
differenceInMinutes,
|
||||
format,
|
||||
getDay,
|
||||
parse,
|
||||
startOfWeek,
|
||||
} from "date-fns";
|
||||
import React from "react";
|
||||
import { Calendar, dateFnsLocalizer } from "react-big-calendar";
|
||||
import { useMount } from "react-use";
|
||||
|
||||
import DateNavigationToolbar from "./date-navigation-toolbar";
|
||||
import { DateTimeOption, DateTimePickerProps } from "./types";
|
||||
import { formatDateWithoutTime, formatDateWithoutTz } from "./utils";
|
||||
|
||||
const localizer = dateFnsLocalizer({
|
||||
format,
|
||||
parse,
|
||||
startOfWeek: (date: Date | number) => startOfWeek(date, { weekStartsOn: 1 }),
|
||||
getDay,
|
||||
locales: {},
|
||||
});
|
||||
|
||||
const WeekCalendar: React.VoidFunctionComponent<DateTimePickerProps> = ({
|
||||
title,
|
||||
options,
|
||||
onNavigate,
|
||||
date,
|
||||
onChange,
|
||||
duration,
|
||||
onChangeDuration,
|
||||
}) => {
|
||||
const [scrollToTime, setScrollToTime] = React.useState<Date>();
|
||||
|
||||
useMount(() => {
|
||||
// Bit of a hack to force rbc to scroll to the right time when we close/open a modal
|
||||
setScrollToTime(addMinutes(date, -60));
|
||||
});
|
||||
|
||||
return (
|
||||
<Calendar
|
||||
events={options.map((option) => {
|
||||
if (option.type === "date") {
|
||||
return { title, start: new Date(option.date) };
|
||||
} else {
|
||||
return {
|
||||
title,
|
||||
start: new Date(option.start),
|
||||
end: new Date(option.end),
|
||||
};
|
||||
}
|
||||
})}
|
||||
onNavigate={onNavigate}
|
||||
date={date}
|
||||
className="h-[calc(100vh-220px)] max-h-[800px] min-h-[400px] w-full"
|
||||
defaultView="week"
|
||||
views={["week"]}
|
||||
selectable={true}
|
||||
localizer={localizer}
|
||||
onSelectEvent={(event) => {
|
||||
onChange(
|
||||
options.filter(
|
||||
(option) =>
|
||||
!(
|
||||
option.type === "timeSlot" &&
|
||||
option.start === formatDateWithoutTz(event.start) &&
|
||||
event.end &&
|
||||
option.end === formatDateWithoutTz(event.end)
|
||||
),
|
||||
),
|
||||
);
|
||||
}}
|
||||
components={{
|
||||
toolbar: (props) => {
|
||||
return (
|
||||
<DateNavigationToolbar
|
||||
year={props.date.getFullYear()}
|
||||
label={props.label}
|
||||
onPrevious={() => {
|
||||
props.onNavigate("PREV");
|
||||
}}
|
||||
onToday={() => {
|
||||
props.onNavigate("TODAY");
|
||||
}}
|
||||
onNext={() => {
|
||||
props.onNavigate("NEXT");
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
eventWrapper: (props) => {
|
||||
return (
|
||||
<div
|
||||
// onClick prop doesn't work properly. Seems like some other element is cancelling the event before it reaches this element
|
||||
onMouseUp={props.onClick}
|
||||
className="absolute p-1 ml-1 max-h-full hover:bg-opacity-50 transition-colors cursor-pointer overflow-hidden bg-green-100 bg-opacity-80 text-green-500 rounded-md text-xs"
|
||||
style={{
|
||||
top: `calc(${props.style?.top}% + 4px)`,
|
||||
height: `calc(${props.style?.height}% - 8px)`,
|
||||
left: `${props.style?.xOffset}%`,
|
||||
width: `calc(${props.style?.width}%)`,
|
||||
}}
|
||||
>
|
||||
<div>{format(props.event.start, "p")}</div>
|
||||
<div className="font-bold w-full truncate">
|
||||
{props.event.title}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
week: {
|
||||
header: ({ date }: any) => {
|
||||
const dateString = formatDateWithoutTime(date);
|
||||
const selectedOption = options.find((option) => {
|
||||
return option.type === "date" && option.date === dateString;
|
||||
});
|
||||
return (
|
||||
<span
|
||||
onClick={() => {
|
||||
if (!selectedOption) {
|
||||
onChange([
|
||||
...options,
|
||||
{
|
||||
type: "date",
|
||||
date: formatDateWithoutTime(date),
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
onChange(
|
||||
options.filter((option) => option !== selectedOption),
|
||||
);
|
||||
}
|
||||
}}
|
||||
className={clsx(
|
||||
"inline-flex w-full justify-center hover:text-gray-700 hover:bg-slate-50 rounded-md items-center text-sm py-2",
|
||||
{
|
||||
"bg-green-50 text-green-600 hover:bg-opacity-75 hover:bg-green-50 hover:text-green-600":
|
||||
!!selectedOption,
|
||||
},
|
||||
)}
|
||||
>
|
||||
<span className="font-normal opacity-50 mr-1">
|
||||
{format(date, "E")}
|
||||
</span>
|
||||
<span className="font-medium">{format(date, "dd")}</span>
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
timeSlotWrapper: ({ children }) => {
|
||||
return <div className="h-12 text-xs text-gray-500">{children}</div>;
|
||||
},
|
||||
}}
|
||||
step={15}
|
||||
onSelectSlot={({ start, end, action }) => {
|
||||
// on select slot
|
||||
const startDate = new Date(start);
|
||||
const endDate = new Date(end);
|
||||
|
||||
const newEvent: DateTimeOption = {
|
||||
type: "timeSlot",
|
||||
start: formatDateWithoutTz(startDate),
|
||||
end: formatDateWithoutTz(endDate),
|
||||
};
|
||||
|
||||
if (action === "select") {
|
||||
const diff = differenceInMinutes(endDate, startDate);
|
||||
if (diff < 60 * 24) {
|
||||
onChangeDuration(diff);
|
||||
}
|
||||
} else {
|
||||
newEvent.end = formatDateWithoutTz(addMinutes(startDate, duration));
|
||||
}
|
||||
|
||||
const alreadyExists = options.some(
|
||||
(option) =>
|
||||
option.type === "timeSlot" &&
|
||||
option.start === newEvent.start &&
|
||||
option.end === newEvent.end,
|
||||
);
|
||||
|
||||
if (!alreadyExists) {
|
||||
onChange([...options, newEvent]);
|
||||
}
|
||||
}}
|
||||
scrollToTime={scrollToTime}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default WeekCalendar;
|
17
components/forms/types.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { PollDetailsData } from "./poll-details-form";
|
||||
import { PollOptionsData } from "./poll-options-form/poll-options-form";
|
||||
import { UserDetailsData } from "./user-details-form";
|
||||
|
||||
export interface NewEventData {
|
||||
currentStep: number;
|
||||
eventDetails?: Partial<PollDetailsData>;
|
||||
options?: Partial<PollOptionsData>;
|
||||
userDetails?: Partial<UserDetailsData>;
|
||||
}
|
||||
export interface PollFormProps<T extends Record<string, any>> {
|
||||
onSubmit: (data: T) => void;
|
||||
onChange?: (data: Partial<T>) => void;
|
||||
defaultValues?: Partial<T>;
|
||||
name?: string;
|
||||
className?: string;
|
||||
}
|
71
components/forms/user-details-form.tsx
Normal file
|
@ -0,0 +1,71 @@
|
|||
import clsx from "clsx";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import * as React from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { requiredString } from "../../utils/form-validation";
|
||||
import { PollFormProps } from "./types";
|
||||
|
||||
export interface UserDetailsData {
|
||||
name: string;
|
||||
contact: string;
|
||||
}
|
||||
|
||||
export const UserDetailsForm: React.VoidFunctionComponent<
|
||||
PollFormProps<UserDetailsData>
|
||||
> = ({ name, defaultValues, onSubmit, onChange, className }) => {
|
||||
const { t } = useTranslation("app");
|
||||
const {
|
||||
handleSubmit,
|
||||
register,
|
||||
watch,
|
||||
formState: { errors },
|
||||
} = useForm<UserDetailsData>({ defaultValues });
|
||||
|
||||
React.useEffect(() => {
|
||||
if (onChange) {
|
||||
const subscription = watch(onChange);
|
||||
return () => {
|
||||
subscription.unsubscribe();
|
||||
};
|
||||
}
|
||||
}, [watch, onChange]);
|
||||
|
||||
return (
|
||||
<form
|
||||
id={name}
|
||||
className={className}
|
||||
style={{ width: 400 }}
|
||||
onSubmit={handleSubmit(onSubmit)}
|
||||
>
|
||||
<div className="formField">
|
||||
<label htmlFor="name">{t("name")}</label>
|
||||
<input
|
||||
type="text"
|
||||
id="name"
|
||||
className={clsx("input w-full", {
|
||||
"input-error": errors.name,
|
||||
})}
|
||||
placeholder={t("namePlaceholder")}
|
||||
{...register("name", { validate: requiredString })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="formField">
|
||||
<label htmlFor="contact">{t("email")}</label>
|
||||
<input
|
||||
id="contact"
|
||||
className={clsx("input w-full", {
|
||||
"input-error": errors.contact,
|
||||
})}
|
||||
placeholder={t("emailPlaceholder")}
|
||||
{...register("contact", {
|
||||
validate: (value) => {
|
||||
return /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(value);
|
||||
},
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
27
components/full-page-loader.tsx
Normal file
|
@ -0,0 +1,27 @@
|
|||
import clsx from "clsx";
|
||||
import * as React from "react";
|
||||
|
||||
import Spinner from "./icons/spinner.svg";
|
||||
|
||||
interface FullPageLoaderProps {
|
||||
className?: string;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
const FullPageLoader: React.VoidFunctionComponent<FullPageLoaderProps> = ({
|
||||
children,
|
||||
className,
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
className={clsx(" h-full flex items-center justify-center", className)}
|
||||
>
|
||||
<div className="bg-indigo-500 text-white text-sm px-4 py-3 shadow-sm rounded-lg flex items-center">
|
||||
<Spinner className="h-5 mr-3 animate-spin" />
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default FullPageLoader;
|
19
components/header.tsx
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { useTranslation } from "next-i18next";
|
||||
import React from "react";
|
||||
|
||||
const Header: React.FunctionComponent<{ className?: string }> = (props) => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div
|
||||
className="h-10 shrink-0 border-gray-200 px-6 flex items-center"
|
||||
{...props}
|
||||
>
|
||||
<div className="text-base font-bold text-gray-400 uppercase">
|
||||
{t("appName")}
|
||||
</div>
|
||||
<div className="ml-2 text-xs text-gray-400">v2-alpha</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Header;
|
119
components/headless-date-picker.tsx
Normal file
|
@ -0,0 +1,119 @@
|
|||
import {
|
||||
addDays,
|
||||
addMonths,
|
||||
format,
|
||||
getMonth,
|
||||
isSameDay,
|
||||
isWeekend,
|
||||
startOfMonth,
|
||||
startOfWeek,
|
||||
} from "date-fns";
|
||||
import React from "react";
|
||||
|
||||
interface DayProps {
|
||||
date: Date;
|
||||
day: string;
|
||||
weekend: boolean;
|
||||
outOfMonth: boolean;
|
||||
today: boolean;
|
||||
selected: boolean;
|
||||
}
|
||||
|
||||
interface HeadlessDatePickerOptions {
|
||||
onSelectionChange?: (selection: Date[]) => void;
|
||||
date?: Date;
|
||||
selection?: Date[];
|
||||
onNavigationChange?: (date: Date) => void;
|
||||
}
|
||||
|
||||
const today = new Date();
|
||||
|
||||
export const useHeadlessDatePicker = (
|
||||
options?: HeadlessDatePickerOptions,
|
||||
): {
|
||||
label: string;
|
||||
next: () => void;
|
||||
prev: () => void;
|
||||
today: () => void;
|
||||
daysOfWeek: string[];
|
||||
days: DayProps[];
|
||||
navigationDate: Date;
|
||||
selection: Date[];
|
||||
toggle: (date: Date) => void;
|
||||
} => {
|
||||
const [localSelection, setSelection] = React.useState<Date[]>([]);
|
||||
const selection = options?.selection ?? localSelection;
|
||||
const [localNavigationDate, setNavigationDate] = React.useState(today);
|
||||
const navigationDate = options?.date ?? localNavigationDate;
|
||||
|
||||
const firstDayOfMonth = startOfMonth(navigationDate);
|
||||
const firstDayOfFirstWeek = startOfWeek(firstDayOfMonth, { weekStartsOn: 1 });
|
||||
|
||||
const currentMonth = getMonth(navigationDate);
|
||||
|
||||
const days: DayProps[] = [];
|
||||
|
||||
const daysOfWeek: string[] = [];
|
||||
|
||||
for (let i = 0; i < 7; i++) {
|
||||
daysOfWeek.push(format(addDays(firstDayOfFirstWeek, i), "EE"));
|
||||
}
|
||||
|
||||
let reachedEnd = false;
|
||||
let i = 0;
|
||||
do {
|
||||
const d = addDays(firstDayOfFirstWeek, i);
|
||||
days.push({
|
||||
date: d,
|
||||
day: format(d, "d"),
|
||||
weekend: isWeekend(d),
|
||||
outOfMonth: getMonth(d) !== currentMonth,
|
||||
today: isSameDay(d, today),
|
||||
selected: selection.some((selectedDate) => isSameDay(selectedDate, d)),
|
||||
});
|
||||
i++;
|
||||
reachedEnd =
|
||||
i > 34 && i % 7 === 0 && addDays(d, 1).getMonth() !== currentMonth;
|
||||
} while (reachedEnd === false);
|
||||
|
||||
return {
|
||||
navigationDate,
|
||||
label: format(navigationDate, "MMMM yyyy"),
|
||||
next: () => {
|
||||
const newDate = startOfMonth(addMonths(navigationDate, 1));
|
||||
if (!options?.date) {
|
||||
setNavigationDate(newDate);
|
||||
}
|
||||
options?.onNavigationChange?.(newDate);
|
||||
},
|
||||
prev: () => {
|
||||
const newDate = startOfMonth(addMonths(navigationDate, -1));
|
||||
if (!options?.date) {
|
||||
setNavigationDate(newDate);
|
||||
}
|
||||
options?.onNavigationChange?.(newDate);
|
||||
},
|
||||
today: () => {
|
||||
const newDate = today;
|
||||
if (!options?.date) {
|
||||
setNavigationDate(newDate);
|
||||
}
|
||||
options?.onNavigationChange?.(newDate);
|
||||
},
|
||||
days,
|
||||
daysOfWeek,
|
||||
selection: options?.selection ?? selection,
|
||||
toggle: (date) => {
|
||||
if (options?.selection) {
|
||||
// ignore, selection is controlled externally
|
||||
return;
|
||||
}
|
||||
const index = selection.indexOf(date);
|
||||
if (index === -1) {
|
||||
setSelection((s) => [...s, date]);
|
||||
} else {
|
||||
setSelection((s) => s.splice(index, 1));
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
3
components/home/ban-ads.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 0a10 10 0 110 20 10 10 0 010-20zm4.905 3.68A8 8 0 003.68 14.906l3.296-3.296-.007-.022H5.531l-.253.835H4L5.44 8.06h1.62l.86 2.606.64-.64V8.06h1.662c.1 0 .197.004.291.013l4.393-4.393zm-4.908 7.738l1.222-1.223v.046c0 .305-.04.542-.121.712a.703.703 0 01-.35.36 1.32 1.32 0 01-.551.105h-.2zM8.99 12.423h1.248c.443 0 .828-.086 1.153-.26.325-.174.577-.424.754-.75.178-.326.266-.717.266-1.171 0-.395-.067-.74-.202-1.038l4.11-4.11A8 8 0 015.095 16.32l3.896-3.897zm5.802-3.332a.46.46 0 01.16.332h1.134a1.34 1.34 0 00-.214-.748 1.367 1.367 0 00-.594-.498A2.177 2.177 0 0014.365 8c-.345 0-.651.058-.918.175-.266.116-.474.279-.625.488a1.2 1.2 0 00-.221.726c-.002.341.108.61.33.808.223.196.528.336.914.42l.435.093c.162.036.29.074.385.115.096.04.164.086.205.137a.27.27 0 01.066.174.307.307 0 01-.068.19.43.43 0 01-.194.13.931.931 0 01-.318.047.985.985 0 01-.39-.07.558.558 0 01-.251-.207.668.668 0 01-.1-.337H12.49c.001.365.08.665.234.9.156.232.375.405.656.517.283.112.614.168.993.168.37 0 .686-.051.949-.155.264-.104.467-.255.609-.454.142-.199.214-.442.215-.729a1.337 1.337 0 00-.08-.46 1.055 1.055 0 00-.242-.38 1.475 1.475 0 00-.421-.295 2.691 2.691 0 00-.62-.203l-.358-.076a1.988 1.988 0 01-.269-.073.836.836 0 01-.185-.09.345.345 0 01-.107-.112.278.278 0 01-.028-.143.289.289 0 01.058-.17.361.361 0 01.17-.118.854.854 0 01.3-.044c.193 0 .335.04.43.119zm-8.526.17l.435 1.44h-.904l.435-1.44h.034z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
59
components/home/bonus.tsx
Normal file
|
@ -0,0 +1,59 @@
|
|||
import * as React from "react";
|
||||
import Ban from "./ban-ads.svg";
|
||||
import Code from "@/components/icons/code.svg";
|
||||
import Server from "@/components/icons/server.svg";
|
||||
import CursorClick from "@/components/icons/cursor-click.svg";
|
||||
|
||||
const Bonus: React.VoidFunctionComponent = () => {
|
||||
return (
|
||||
<div className="py-16 max-w-7xl mx-auto px-8">
|
||||
<h2 className="heading">Principles</h2>
|
||||
<p className="subheading">We're not like the others</p>
|
||||
<div className="grid grid-cols-4 gap-16">
|
||||
<div className="col-span-4 md:col-span-2 lg:col-span-1">
|
||||
<div className="mb-4 text-slate-400">
|
||||
<CursorClick className="w-16" />
|
||||
</div>
|
||||
<h3 className="heading-sm">No login required</h3>
|
||||
<div className="text text-base leading-relaxed">
|
||||
We keep things simple and don't ask for more than what we need.
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-span-4 md:col-span-2 lg:col-span-1">
|
||||
<div className="mb-4 text-slate-400">
|
||||
<Code className="w-16" />
|
||||
</div>
|
||||
<h3 className="heading-sm">Open-source</h3>
|
||||
<div className="text text-base leading-relaxed">
|
||||
The codebase is fully open-source and{" "}
|
||||
<a href="https://github.com/lukevella/Rallly">
|
||||
available on github
|
||||
</a>
|
||||
.
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-span-4 md:col-span-2 lg:col-span-1">
|
||||
<div className="mb-4 text-slate-400">
|
||||
<Server className="w-16" />
|
||||
</div>
|
||||
<h3 className="heading-sm">Self-hostable</h3>
|
||||
<div className="text text-base leading-relaxed">
|
||||
Run it on your own server to get full control of your data.
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-span-4 md:col-span-2 lg:col-span-1">
|
||||
<div className="mb-4 text-slate-400">
|
||||
<Ban className="w-16" />
|
||||
</div>
|
||||
<h3 className="heading-sm">Ad-free</h3>
|
||||
<div className="text text-base leading-relaxed">
|
||||
You can give your ad-blocker a rest – You won't need it
|
||||
here.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Bonus;
|
64
components/home/features.tsx
Normal file
|
@ -0,0 +1,64 @@
|
|||
import Bell from "@/components/icons/bell.svg";
|
||||
import Chat from "@/components/icons/chat.svg";
|
||||
import Clock from "@/components/icons/clock.svg";
|
||||
import DeviceMobile from "@/components/icons/device-mobile.svg";
|
||||
import * as React from "react";
|
||||
|
||||
const Features: React.VoidFunctionComponent = () => {
|
||||
return (
|
||||
<div className="py-16 px-8 max-w-7xl mx-auto">
|
||||
<h2 className="heading">Features</h2>
|
||||
<p className="subheading">Everything you need to get the job done</p>
|
||||
<div className="grid grid-cols-2 gap-12">
|
||||
<div className="col-span-2 md:col-span-1">
|
||||
<div className="p-3 bg-green-100/50 text-green-400 inline-block rounded-2xl mb-4">
|
||||
<Clock className="w-8 h-8" />
|
||||
</div>
|
||||
<h3 className="heading-sm flex items-center">
|
||||
Time slots
|
||||
<span className="ml-2 font-normal text-sm bg-green-500 text-white rounded-full px-2 py-1">
|
||||
New
|
||||
</span>
|
||||
</h3>
|
||||
<p className="text">
|
||||
If you need more granular options, Rallly lets you choose time slots
|
||||
as options. If your participants are international, they can see
|
||||
times in on their own time zone.
|
||||
</p>
|
||||
</div>
|
||||
<div className="col-span-2 md:col-span-1">
|
||||
<div className="p-3 bg-cyan-100/50 text-cyan-400 inline-block rounded-2xl mb-4">
|
||||
<DeviceMobile className="w-8 h-8" />
|
||||
</div>
|
||||
<h3 className="heading-sm">Mobile friendly design</h3>
|
||||
<p className="text">
|
||||
Rallly is optimized to look and work great on mobile devices so you
|
||||
and your participants can use it on the go.
|
||||
</p>
|
||||
</div>
|
||||
<div className="col-span-2 md:col-span-1">
|
||||
<div className="p-3 bg-rose-100/50 text-rose-400 inline-block rounded-2xl mb-4">
|
||||
<Bell className="w-8 h-8" />
|
||||
</div>
|
||||
<h3 className="heading-sm">Notifications</h3>
|
||||
<p className="text">
|
||||
Need help staying on top of things? Rallly can send you an email
|
||||
whenever participants vote or comment on your poll.
|
||||
</p>
|
||||
</div>
|
||||
<div className="col-span-2 md:col-span-1">
|
||||
<div className="p-3 bg-yellow-100/50 text-yellow-400 inline-block rounded-2xl mb-4">
|
||||
<Chat className="w-8 h-8" />
|
||||
</div>
|
||||
<h3 className="heading-sm">Comments</h3>
|
||||
<p className="text">
|
||||
Got a question or just have something to say? You and your
|
||||
participants can comment on polls to start a discussion.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Features;
|
3
components/home/github.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg width="24" height="24" fill="currentColor" class="text-purple-600 mr-3 text-opacity-50 transform">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 2C6.477 2 2 6.463 2 11.97c0 4.404 2.865 8.14 6.839 9.458.5.092.682-.216.682-.48 0-.236-.008-.864-.013-1.695-2.782.602-3.369-1.337-3.369-1.337-.454-1.151-1.11-1.458-1.11-1.458-.908-.618.069-.606.069-.606 1.003.07 1.531 1.027 1.531 1.027.892 1.524 2.341 1.084 2.91.828.092-.643.35-1.083.636-1.332-2.22-.251-4.555-1.107-4.555-4.927 0-1.088.39-1.979 1.029-2.675-.103-.252-.446-1.266.098-2.638 0 0 .84-.268 2.75 1.022A9.606 9.606 0 0112 6.82c.85.004 1.705.114 2.504.336 1.909-1.29 2.747-1.022 2.747-1.022.546 1.372.202 2.386.1 2.638.64.696 1.028 1.587 1.028 2.675 0 3.83-2.339 4.673-4.566 4.92.359.307.678.915.678 1.846 0 1.332-.012 2.407-.012 2.734 0 .267.18.577.688.48C19.137 20.107 22 16.373 22 11.969 22 6.463 17.522 2 12 2z"></path>
|
||||
</svg>
|
After Width: | Height: | Size: 898 B |
80
components/home/hero.tsx
Normal file
|
@ -0,0 +1,80 @@
|
|||
import { motion } from "framer-motion";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import Link from "next/link";
|
||||
import * as React from "react";
|
||||
import { UserAvatarProvider } from "../poll/user-avatar";
|
||||
import PollDemo from "./poll-demo";
|
||||
import ScribbleArrow from "./scribble-arrow.svg";
|
||||
|
||||
const Hero: React.VoidFunctionComponent = () => {
|
||||
const { t } = useTranslation("homepage");
|
||||
const names = ["Peter", "Christine", "Samantha", "Joseph"];
|
||||
|
||||
return (
|
||||
<div className="lg:flex p-8 items-end max-w-7xl mx-auto">
|
||||
<div className="my-8 text-center lg:text-left">
|
||||
<h1 className="text-5xl font-bold">
|
||||
Schedule
|
||||
<br />
|
||||
<span className="text-indigo-500">group meetings</span>
|
||||
<br />
|
||||
with ease
|
||||
</h1>
|
||||
<div className="text-xl text-gray-400 mb-12">
|
||||
Find the right date without the back and forth.
|
||||
</div>
|
||||
<div className="space-x-3">
|
||||
<Link href="/new">
|
||||
<a className="focus:ring-2 focus:ring-indigo-200 transition-all text-white bg-indigo-500 hover:bg-indigo-500/90 active:bg-indigo-600/90 px-5 py-3 font-semibold hover:text-white hover:no-underline shadow-sm hover:shadow-md rounded-lg">
|
||||
{t("getStarted")}
|
||||
</a>
|
||||
</Link>
|
||||
<Link href="/demo">
|
||||
<a
|
||||
className="text-white focus:ring-2 focus:ring-indigo-200 transition-all bg-slate-500 hover:bg-slate-500/90 active:bg-slate-600/90 px-5 py-3 font-semibold hover:text-white hover:no-underline shadow-sm hover:shadow-md rounded-lg"
|
||||
rel="nofollow"
|
||||
>
|
||||
{t("viewDemo")}
|
||||
</a>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<div className="hidden mt-16 lg:mt-0 lg:ml-24 pointer-events-none select-none h-[380px] md:flex items-end justify-center">
|
||||
<UserAvatarProvider seed="mock" names={names}>
|
||||
<div className="inline-block relative">
|
||||
<motion.div
|
||||
className="absolute z-20 border-4 shadow-md bg-indigo-200/10 rounded-2xl border-indigo-500 h-full"
|
||||
initial={{ opacity: 0, width: 100, scale: 1.2, translateX: 384 }}
|
||||
animate={{ opacity: 1, scale: 1.1 }}
|
||||
transition={{ type: "spring", delay: 1 }}
|
||||
/>
|
||||
<motion.div
|
||||
className="absolute bg-indigo-500 text-slate-100 py-1 px-3 rounded-full z-20 text-sm"
|
||||
initial={{
|
||||
opacity: 0,
|
||||
right: 190,
|
||||
top: -65,
|
||||
translateY: 50,
|
||||
}}
|
||||
animate={{ opacity: 1, translateY: 0 }}
|
||||
transition={{ type: "spring", delay: 2 }}
|
||||
>
|
||||
Perfect! 🤩
|
||||
<ScribbleArrow className="absolute text-slate-400 -right-8 top-3" />
|
||||
</motion.div>
|
||||
<motion.div
|
||||
className="shadow-lg rounded-lg"
|
||||
transition={{ type: "spring", delay: 0.5 }}
|
||||
initial={{ opacity: 0, translateY: -100 }}
|
||||
animate={{ opacity: 1, translateY: 0 }}
|
||||
>
|
||||
<PollDemo />
|
||||
</motion.div>
|
||||
</div>
|
||||
</UserAvatarProvider>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Hero;
|
25
components/home/home.tsx
Normal file
|
@ -0,0 +1,25 @@
|
|||
import Head from "next/head";
|
||||
import React from "react";
|
||||
import PageLayout from "../page-layout";
|
||||
import Bonus from "./bonus";
|
||||
import Features from "./features";
|
||||
import Hero from "./hero";
|
||||
|
||||
const Home: React.VoidFunctionComponent = () => {
|
||||
return (
|
||||
<PageLayout>
|
||||
<Head>
|
||||
<title>Rallly - Schedule group meetings</title>
|
||||
</Head>
|
||||
<Hero />
|
||||
<div className="bg-gradient-to-b from-transparent via-white to-white">
|
||||
<Features />
|
||||
</div>
|
||||
<div className="bg-gradient-to-b from-white via-white to-transparent pb-16">
|
||||
<Bonus />
|
||||
</div>
|
||||
</PageLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Home;
|
36
components/home/how-it-works.tsx
Normal file
|
@ -0,0 +1,36 @@
|
|||
import * as React from "react";
|
||||
|
||||
const HowItWorks: React.VoidFunctionComponent = () => {
|
||||
return (
|
||||
<div className="bg-gradient-to-b from-transparent via-white to-white">
|
||||
<div className="py-16 px-8 mx-auto max-w-7xl">
|
||||
<h2 className="heading text-center">How it works</h2>
|
||||
<p className="subheading text-center">It's simple!</p>
|
||||
<div className="grid grid-cols-3 gap-16">
|
||||
<div className="col-span-1">
|
||||
<h3 className="text-xl">Create a poll</h3>
|
||||
<p className="text">
|
||||
Choose options you would like your participants to choose from.
|
||||
</p>
|
||||
</div>
|
||||
<div className="col-span-1">
|
||||
<h3 className="text-xl">Share your link</h3>
|
||||
<p className="text">
|
||||
Share your unique link with your participants to give them access
|
||||
to the page.
|
||||
</p>
|
||||
</div>
|
||||
<div className="col-span-1">
|
||||
<h3 className="text-xl">Vote</h3>
|
||||
<p className="text">
|
||||
Participants vote for the dates they prefer. The option with the
|
||||
most votes wins!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default HowItWorks;
|
1
components/home/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './home';
|
121
components/home/poll-demo.tsx
Normal file
|
@ -0,0 +1,121 @@
|
|||
import { format } from "date-fns";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import * as React from "react";
|
||||
import { useTimeoutFn } from "react-use";
|
||||
import DateCard from "../date-card";
|
||||
import Score from "../poll/score";
|
||||
import UserAvater from "../poll/user-avatar";
|
||||
import VoteIcon from "../poll/vote-icon";
|
||||
|
||||
const sidebarWidth = 180;
|
||||
const participants = [
|
||||
{
|
||||
name: "Reed",
|
||||
color: "bg-sky-400",
|
||||
votes: [0, 2],
|
||||
},
|
||||
{
|
||||
name: "Susan",
|
||||
color: "bg-blue-400",
|
||||
votes: [0, 1, 2],
|
||||
},
|
||||
{
|
||||
name: "Johnny",
|
||||
color: "bg-indigo-400",
|
||||
votes: [2, 3],
|
||||
},
|
||||
{
|
||||
name: "Ben",
|
||||
color: "bg-purple-400",
|
||||
votes: [0, 1, 2, 3],
|
||||
},
|
||||
];
|
||||
|
||||
const options = ["2022-12-14", "2022-12-15", "2022-12-16", "2022-12-17"];
|
||||
|
||||
const PollDemo: React.VoidFunctionComponent = () => {
|
||||
const { t } = useTranslation("app");
|
||||
const [bestOption, setBestOption] = React.useState<number>();
|
||||
useTimeoutFn(() => {
|
||||
setBestOption(2);
|
||||
}, 1500);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="rounded-lg bg-white border shadow-md"
|
||||
style={{ width: 600 }}
|
||||
>
|
||||
<div className="flex border-b shadow-sm">
|
||||
<div
|
||||
className="flex items-center pl-4 pr-2 py-4 shrink-0 font-medium"
|
||||
style={{ width: sidebarWidth }}
|
||||
>
|
||||
<div className="grow h-full flex items-end">
|
||||
{t("participantCount", { count: participants.length })}
|
||||
</div>
|
||||
</div>
|
||||
{options.map((option, i) => {
|
||||
const d = new Date(option);
|
||||
let score = 0;
|
||||
participants.forEach((participant) => {
|
||||
if (participant.votes.includes(i)) {
|
||||
score++;
|
||||
}
|
||||
});
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
className="py-4 text-center shrink-0 transition-colors"
|
||||
style={{ width: 100 }}
|
||||
>
|
||||
<DateCard
|
||||
day={format(d, "dd")}
|
||||
dow={format(d, "E")}
|
||||
month={format(d, "MMM")}
|
||||
annotation={
|
||||
<Score count={score} highlight={i === bestOption} />
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{participants.map((participant, i) => (
|
||||
<div className="flex h-14" key={i}>
|
||||
<div
|
||||
className="flex items-center px-4 shrink-0"
|
||||
style={{ width: sidebarWidth }}
|
||||
>
|
||||
<UserAvater
|
||||
className="mr-2"
|
||||
color={participant.color}
|
||||
name={participant.name}
|
||||
/>
|
||||
<span className="truncate" title={participant.name}>
|
||||
{participant.name}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex">
|
||||
{options.map((_, i) => {
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
className="justify-center items-center flex shrink-0"
|
||||
style={{ width: 100 }}
|
||||
>
|
||||
{participant.votes.some((vote) => vote === i) ? (
|
||||
<VoteIcon type="yes" />
|
||||
) : (
|
||||
<VoteIcon type="no" />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PollDemo;
|
3
components/home/scribble-arrow.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" viewBox="0 0 30 30">
|
||||
<path fill-rule="evenodd" d="M1.11 2.994h.001l.014-.002a17.546 17.546 0 011.383-.055c.902 0 2.175.06 3.643.3 2.944.48 6.612 1.674 9.67 4.498 1.464 1.35 2.55 3.281 3.339 5.492.787 2.204 1.259 4.626 1.535 6.894.27 2.224.35 4.275.36 5.788l-4.245-4.83a1 1 0 10-1.502 1.32l5.94 6.761a1 1 0 001.412.091l6.76-5.94a1 1 0 10-1.32-1.503l-5.045 4.433v-.262a53.57 53.57 0 00-.375-6.1c-.287-2.357-.783-4.935-1.637-7.325-.85-2.383-2.078-4.64-3.865-6.289-3.44-3.176-7.523-4.483-10.704-5.002A24.842 24.842 0 002.508.938a19.54 19.54 0 00-1.492.056 7.207 7.207 0 00-.089.008l-.025.003H.89v.001L1 2l-.11-.994a1 1 0 00.22 1.988" clip-rule="evenodd"/>
|
||||
</svg>
|
After Width: | Height: | Size: 744 B |
30
components/home/stats.tsx
Normal file
|
@ -0,0 +1,30 @@
|
|||
import Link from "next/link";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
const Stats: React.VoidFunctionComponent = () => {
|
||||
const { t } = useTranslation("homepage");
|
||||
return (
|
||||
<div className="py-16">
|
||||
<h2 className="heading text-center">Stats</h2>
|
||||
<p className="subheading text-center">100,000+ polls created</p>
|
||||
<div className="flex space-x-3 justify-center">
|
||||
<Link href="/new">
|
||||
<a className="focus:ring-2 focus:ring-indigo-200 transition-all text-white bg-indigo-500 hover:bg-indigo-500/90 active:bg-indigo-600/90 px-5 py-3 font-semibold hover:text-white hover:no-underline shadow-sm hover:shadow-md rounded-lg">
|
||||
{t("getStarted")}
|
||||
</a>
|
||||
</Link>
|
||||
<Link href="/demo">
|
||||
<a
|
||||
className="text-white focus:ring-2 focus:ring-indigo-200 transition-all bg-slate-500 hover:bg-slate-500/90 active:bg-slate-600/90 px-5 py-3 font-semibold hover:text-white hover:no-underline shadow-sm hover:shadow-md rounded-lg"
|
||||
rel="nofollow"
|
||||
>
|
||||
{t("viewDemo")}
|
||||
</a>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Stats;
|
3
components/icons/annotation.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M18 13V5a2 2 0 00-2-2H4a2 2 0 00-2 2v8a2 2 0 002 2h3l3 3 3-3h3a2 2 0 002-2zM5 7a1 1 0 011-1h8a1 1 0 110 2H6a1 1 0 01-1-1zm1 3a1 1 0 100 2h3a1 1 0 100-2H6z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 313 B |
3
components/icons/arrow-left.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M9.707 16.707a1 1 0 01-1.414 0l-6-6a1 1 0 010-1.414l6-6a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l4.293 4.293a1 1 0 010 1.414z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 292 B |
3
components/icons/arrow-right.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M10.293 3.293a1 1 0 011.414 0l6 6a1 1 0 010 1.414l-6 6a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-4.293-4.293a1 1 0 010-1.414z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 295 B |
3
components/icons/ban.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636" />
|
||||
</svg>
|
After Width: | Height: | Size: 291 B |
4
components/icons/bell-crossed.svg
Normal file
|
@ -0,0 +1,4 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M17.613 15.538a1.188 1.188 0 01-1.673.155L2.996 4.933a1.188 1.188 0 111.519-1.827l12.944 10.759c.505.42.574 1.169.154 1.673z" clip-rule="evenodd"/>
|
||||
<path d="M16 11.202V8a6 6 0 00-9.614-4.79L16 11.203zM4.046 7.256A6 6 0 004 8v3.586l-.707.707A1 1 0 004 14h8.16L4.045 7.256zM7.878 17.121A3 3 0 0013 15H7a3 3 0 00.878 2.121z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 468 B |
4
components/icons/bell.svg
Normal file
|
@ -0,0 +1,4 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path d="M10 2a6 6 0 00-6 6v3.586l-.707.707A1 1 0 004 14h12a1 1 0 00.707-1.707L16 11.586V8a6 6 0 00-6-6zm0 16a3 3 0 01-3-3h6a3 3 0 01-3 3z" />
|
||||
<path fill-rule="evenodd" d="M1.845 8.877c-.552.009-1.012-.434-.973-.985.22-3.078 1.666-5.148 2.891-6.215.417-.363 1.03-.198 1.305.281.274.48.11 1.102-.277 1.496-.778.795-1.712 2.244-1.91 4.408-.05.55-.484 1.006-1.036 1.015zM18.069 8.553c.552-.007.999-.462.944-1.012-.308-3.07-1.811-5.098-3.067-6.13-.426-.351-1.035-.168-1.296.319-.26.486-.078 1.103.32 1.487.8.772 1.775 2.194 2.034 4.351.066.548.512.992 1.064.985z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 674 B |
3
components/icons/calendar.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
||||
</svg>
|
After Width: | Height: | Size: 283 B |
3
components/icons/chat.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M17 8h2a2 2 0 012 2v6a2 2 0 01-2 2h-2v4l-4-4H9a1.994 1.994 0 01-1.414-.586m0 0L11 14h4a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2v4l.586-.586z" />
|
||||
</svg>
|
After Width: | Height: | Size: 354 B |
3
components/icons/check-circle.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 292 B |
3
components/icons/check.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 273 B |
3
components/icons/chevron-down.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 273 B |
3
components/icons/chevron-left.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fillRule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clipRule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 274 B |
3
components/icons/chevron-right.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 273 B |
3
components/icons/clock.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
After Width: | Height: | Size: 240 B |
3
components/icons/code.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" />
|
||||
</svg>
|
After Width: | Height: | Size: 234 B |
3
components/icons/cog.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M11.49 3.17c-.38-1.56-2.6-1.56-2.98 0a1.532 1.532 0 01-2.286.948c-1.372-.836-2.942.734-2.106 2.106.54.886.061 2.042-.947 2.287-1.561.379-1.561 2.6 0 2.978a1.532 1.532 0 01.947 2.287c-.836 1.372.734 2.942 2.106 2.106a1.532 1.532 0 012.287.947c.379 1.561 2.6 1.561 2.978 0a1.533 1.533 0 012.287-.947c1.372.836 2.942-.734 2.106-2.106a1.533 1.533 0 01.947-2.287c1.561-.379 1.561-2.6 0-2.978a1.532 1.532 0 01-.947-2.287c.836-1.372-.734-2.942-2.106-2.106a1.532 1.532 0 01-2.287-.947zM10 13a3 3 0 100-6 3 3 0 000 6z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 667 B |
3
components/icons/cursor-click.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15 15l-2 5L9 9l11 4-5 2zm0 0l5 5M7.188 2.239l.777 2.897M5.136 7.965l-2.898-.777M13.95 4.05l-2.122 2.122m-5.657 5.656l-2.12 2.122" />
|
||||
</svg>
|
After Width: | Height: | Size: 326 B |
3
components/icons/device-mobile.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z" />
|
||||
</svg>
|
After Width: | Height: | Size: 272 B |
3
components/icons/document-search.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M10 21h7a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v11m0 5l4.879-4.879m0 0a3 3 0 104.243-4.242 3 3 0 00-4.243 4.242z" />
|
||||
</svg>
|
After Width: | Height: | Size: 352 B |
3
components/icons/dots-horizontal.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M6 10a2 2 0 11-4 0 2 2 0 014 0zM12 10a2 2 0 11-4 0 2 2 0 014 0zM16 12a2 2 0 100-4 2 2 0 000 4z" />
|
||||
</svg>
|
After Width: | Height: | Size: 213 B |
3
components/icons/dots-vertical.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M10 6a2 2 0 110-4 2 2 0 010 4zM10 12a2 2 0 110-4 2 2 0 010 4zM10 18a2 2 0 110-4 2 2 0 010 4z" />
|
||||
</svg>
|
After Width: | Height: | Size: 215 B |
4
components/icons/duplicate.svg
Normal file
|
@ -0,0 +1,4 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M7 9a2 2 0 012-2h6a2 2 0 012 2v6a2 2 0 01-2 2H9a2 2 0 01-2-2V9z" />
|
||||
<path d="M5 3a2 2 0 00-2 2v6a2 2 0 002 2V5h8a2 2 0 00-2-2H5z" />
|
||||
</svg>
|
After Width: | Height: | Size: 249 B |
3
components/icons/emoji-sad.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M9.172 16.172a4 4 0 015.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
After Width: | Height: | Size: 279 B |
3
components/icons/exclamation.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 272 B |
3
components/icons/graph1.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M2 11a1 1 0 011-1h2a1 1 0 011 1v5a1 1 0 01-1 1H3a1 1 0 01-1-1v-5zM8 7a1 1 0 011-1h2a1 1 0 011 1v9a1 1 0 01-1 1H9a1 1 0 01-1-1V7zM14 4a1 1 0 011-1h2a1 1 0 011 1v12a1 1 0 01-1 1h-2a1 1 0 01-1-1V4z" />
|
||||
</svg>
|
After Width: | Height: | Size: 313 B |
3
components/icons/hand.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M7 11.5V14m0-2.5v-6a1.5 1.5 0 113 0m-3 6a1.5 1.5 0 00-3 0v2a7.5 7.5 0 0015 0v-5a1.5 1.5 0 00-3 0m-6-3V11m0-5.5v-1a1.5 1.5 0 013 0v1m0 0V11m0-5.5a1.5 1.5 0 013 0v3m0 0V11" />
|
||||
</svg>
|
After Width: | Height: | Size: 366 B |
3
components/icons/home.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
|
||||
</svg>
|
After Width: | Height: | Size: 341 B |
3
components/icons/location-marker.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fillRule="evenodd" d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z" clipRule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 252 B |
3
components/icons/lock-closed.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
|
||||
</svg>
|
After Width: | Height: | Size: 297 B |
3
components/icons/lock-open.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z" />
|
||||
</svg>
|
After Width: | Height: | Size: 289 B |
3
components/icons/magic.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M5 3v4M3 5h4M6 17v4m-2-2h4m5-16l2.286 6.857L21 12l-5.714 2.143L13 21l-2.286-6.857L5 12l5.714-2.143L13 3z" />
|
||||
</svg>
|
After Width: | Height: | Size: 301 B |
3
components/icons/newspaper.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" />
|
||||
</svg>
|
After Width: | Height: | Size: 331 B |
3
components/icons/pencil-alt.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
|
||||
</svg>
|
After Width: | Height: | Size: 293 B |
4
components/icons/pencil.svg
Normal file
|
@ -0,0 +1,4 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M17.414 2.586a2 2 0 00-2.828 0L7 10.172V13h2.828l7.586-7.586a2 2 0 000-2.828z" />
|
||||
<path fill-rule="evenodd" d="M2 6a2 2 0 012-2h4a1 1 0 010 2H4v10h10v-4a1 1 0 112 0v4a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 338 B |
3
components/icons/plus-circle.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z" clip-rule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 265 B |
3
components/icons/plus-sm.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fillRule="evenodd" d="M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z" clipRule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 246 B |
3
components/icons/save.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4" />
|
||||
</svg>
|
After Width: | Height: | Size: 288 B |
3
components/icons/server.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01" />
|
||||
</svg>
|
After Width: | Height: | Size: 349 B |
3
components/icons/share.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M15 8a3 3 0 10-2.977-2.63l-4.94 2.47a3 3 0 100 4.319l4.94 2.47a3 3 0 10.895-1.789l-4.94-2.47a3.027 3.027 0 000-.74l4.94-2.47C13.456 7.68 14.19 8 15 8z" />
|
||||
</svg>
|
After Width: | Height: | Size: 269 B |
3
components/icons/smile.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M14.828 14.828a4 4 0 01-5.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
After Width: | Height: | Size: 281 B |
3
components/icons/speakerphone.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z" />
|
||||
</svg>
|
After Width: | Height: | Size: 395 B |
4
components/icons/spinner.svg
Normal file
|
@ -0,0 +1,4 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||
<circle opacity="0.25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
<path fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||
</svg>
|
After Width: | Height: | Size: 328 B |
3
components/icons/support.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M18.364 5.636l-3.536 3.536m0 5.656l3.536 3.536M9.172 9.172L5.636 5.636m3.536 9.192l-3.536 3.536M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-5 0a4 4 0 11-8 0 4 4 0 018 0z" />
|
||||
</svg>
|
After Width: | Height: | Size: 357 B |
3
components/icons/table.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
|
||||
</svg>
|
After Width: | Height: | Size: 285 B |
3
components/icons/trash.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
||||
</svg>
|
After Width: | Height: | Size: 321 B |
3
components/icons/user.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
|
||||
</svg>
|
After Width: | Height: | Size: 264 B |
3
components/icons/x-circle.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
After Width: | Height: | Size: 265 B |
3
components/icons/x.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fillRule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clipRule="evenodd" />
|
||||
</svg>
|
After Width: | Height: | Size: 355 B |
13
components/menu-styles.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import clsx from "clsx";
|
||||
|
||||
export const styleMenuItem = ({
|
||||
active,
|
||||
selected,
|
||||
}: {
|
||||
active: boolean;
|
||||
selected: boolean;
|
||||
}) =>
|
||||
clsx("menu-item", {
|
||||
"font-medium": selected,
|
||||
"bg-blue-50": active,
|
||||
});
|
1
components/modal/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { useModal } from "./use-modal";
|
106
components/modal/modal.tsx
Normal file
|
@ -0,0 +1,106 @@
|
|||
import { Dialog, Transition } from "@headlessui/react";
|
||||
import * as React from "react";
|
||||
|
||||
import Button, { ButtonProps } from "../button";
|
||||
|
||||
export interface ModalProps {
|
||||
description?: React.ReactNode;
|
||||
title?: React.ReactNode;
|
||||
okText?: string;
|
||||
cancelText?: string;
|
||||
okButtonProps?: ButtonProps;
|
||||
onOk?: () => void;
|
||||
onCancel?: () => void;
|
||||
footer?: React.ReactNode;
|
||||
content?: React.ReactNode;
|
||||
overlayClosable?: boolean;
|
||||
visible?: boolean;
|
||||
}
|
||||
|
||||
const Modal: React.VoidFunctionComponent<ModalProps> = ({
|
||||
description,
|
||||
title,
|
||||
okText,
|
||||
cancelText,
|
||||
okButtonProps,
|
||||
footer,
|
||||
content,
|
||||
overlayClosable,
|
||||
onCancel,
|
||||
onOk,
|
||||
visible,
|
||||
}) => {
|
||||
const initialFocusRef = React.useRef<HTMLButtonElement>(null);
|
||||
return (
|
||||
<Transition appear={true} as={React.Fragment} show={visible}>
|
||||
<Dialog
|
||||
open={visible}
|
||||
className="fixed z-40 inset-0 overflow-y-auto"
|
||||
initialFocus={initialFocusRef}
|
||||
onClose={() => {
|
||||
if (overlayClosable) onCancel?.();
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center justify-center min-h-screen">
|
||||
<Transition.Child
|
||||
as={React.Fragment}
|
||||
enter="ease-out duration-200"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<Dialog.Overlay className="fixed inset-0 bg-slate-900 bg-opacity-10" />
|
||||
</Transition.Child>
|
||||
<Transition.Child
|
||||
as={React.Fragment}
|
||||
enter="ease-out duration-100"
|
||||
enterFrom="opacity-0 scale-95"
|
||||
enterTo="opacity-100 scale-100"
|
||||
leave="ease-in duration-100"
|
||||
leaveFrom="opacity-100 scale-100"
|
||||
leaveTo="opacity-0 scale-95"
|
||||
>
|
||||
<div className="inline-block w-fit my-8 mx-4 overflow-hidden text-left align-middle transition-all transform bg-white shadow-xl rounded-xl">
|
||||
{content ?? (
|
||||
<div className="p-4 max-w-lg">
|
||||
{title ? <Dialog.Title>{title}</Dialog.Title> : null}
|
||||
{description ? (
|
||||
<Dialog.Description>{description}</Dialog.Description>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
{footer ?? (
|
||||
<div className="px-4 space-x-3 h-14 flex justify-end bg-slate-50 items-center border-t">
|
||||
{cancelText ? (
|
||||
<Button
|
||||
ref={initialFocusRef}
|
||||
onClick={() => {
|
||||
onCancel?.();
|
||||
}}
|
||||
>
|
||||
{cancelText}
|
||||
</Button>
|
||||
) : null}
|
||||
{okText ? (
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
onOk?.();
|
||||
}}
|
||||
{...okButtonProps}
|
||||
>
|
||||
{okText}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Transition.Child>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Transition>
|
||||
);
|
||||
};
|
||||
|
||||
export default Modal;
|
27
components/modal/use-modal.tsx
Normal file
|
@ -0,0 +1,27 @@
|
|||
import React from "react";
|
||||
|
||||
import Modal, { ModalProps } from "./modal";
|
||||
|
||||
type OpenModalFn = () => void;
|
||||
type CloseModalFn = () => void;
|
||||
|
||||
export const useModal = (
|
||||
props?: ModalProps,
|
||||
): [React.ReactElement<ModalProps>, OpenModalFn, CloseModalFn] => {
|
||||
const [visible, setVisible] = React.useState(false);
|
||||
const modal = (
|
||||
<Modal
|
||||
{...props}
|
||||
visible={visible}
|
||||
onOk={() => {
|
||||
props?.onOk?.();
|
||||
setVisible(false);
|
||||
}}
|
||||
onCancel={() => {
|
||||
props?.onCancel?.();
|
||||
setVisible(false);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
return [modal, () => setVisible(true), () => setVisible(false)];
|
||||
};
|
36
components/name-input.tsx
Normal file
|
@ -0,0 +1,36 @@
|
|||
import clsx from "clsx";
|
||||
import * as React from "react";
|
||||
|
||||
import UserAvater from "./poll/user-avatar";
|
||||
|
||||
interface NameInputProps
|
||||
extends React.DetailedHTMLProps<
|
||||
React.InputHTMLAttributes<HTMLInputElement>,
|
||||
HTMLInputElement
|
||||
> {
|
||||
value?: string;
|
||||
defaultValue?: string;
|
||||
}
|
||||
|
||||
const NameInput: React.ForwardRefRenderFunction<
|
||||
HTMLInputElement,
|
||||
NameInputProps
|
||||
> = ({ value, defaultValue, className, ...forwardProps }, ref) => {
|
||||
return (
|
||||
<div className="flex items-center relative">
|
||||
<UserAvater
|
||||
name={value ?? defaultValue ?? ""}
|
||||
className="absolute left-2"
|
||||
/>
|
||||
<input
|
||||
ref={ref}
|
||||
className={clsx("input pl-[35px]", className)}
|
||||
placeholder="Your name…"
|
||||
value={value}
|
||||
{...forwardProps}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.forwardRef(NameInput);
|
114
components/page-layout.tsx
Normal file
|
@ -0,0 +1,114 @@
|
|||
import Link from "next/link";
|
||||
import * as React from "react";
|
||||
import Github from "./home/github.svg";
|
||||
import Logo from "../public/logo.svg";
|
||||
import Footer from "./page-layout/footer";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import clsx from "clsx";
|
||||
import DotsVertical from "@/components/icons/dots-vertical.svg";
|
||||
import dynamic from "next/dynamic";
|
||||
import { createBreakpoint } from "react-use";
|
||||
|
||||
const Popover = dynamic(() => import("./popover"), { ssr: false });
|
||||
export interface PageLayoutProps {
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
const useBreakpoint = createBreakpoint({ sm: 640, md: 768, lg: 1024 });
|
||||
|
||||
const Menu: React.VoidFunctionComponent<{ className: string }> = ({
|
||||
className,
|
||||
}) => {
|
||||
const { pathname } = useRouter();
|
||||
return (
|
||||
<nav className={className}>
|
||||
<Link href="/">
|
||||
<a
|
||||
className={clsx(
|
||||
"text-gray-400 hover:text-indigo-500 hover:underline-offset-2 hover:no-underline transition-colors",
|
||||
{
|
||||
"font-bold text-gray-600 pointer-events-none":
|
||||
pathname === "/home",
|
||||
},
|
||||
)}
|
||||
>
|
||||
Home
|
||||
</a>
|
||||
</Link>
|
||||
<Link href="https://blog.rallly.co">
|
||||
<a
|
||||
className={clsx(
|
||||
"text-gray-400 hover:text-indigo-500 hover:underline-offset-2 hover:no-underline transition-colors",
|
||||
)}
|
||||
>
|
||||
Blog
|
||||
</a>
|
||||
</Link>
|
||||
<Link href="/support">
|
||||
<a
|
||||
className={clsx(
|
||||
"text-gray-400 hover:text-indigo-500 hover:underline-offset-2 hover:no-underline transition-colors",
|
||||
{
|
||||
"font-bold text-gray-600 pointer-events-none":
|
||||
pathname === "/support",
|
||||
},
|
||||
)}
|
||||
>
|
||||
Support
|
||||
</a>
|
||||
</Link>
|
||||
<Link href="https://github.com/lukevella/Rallly">
|
||||
<a className="text-gray-400 hover:text-indigo-500 hover:underline-offset-2 hover:no-underline transition-colors">
|
||||
<Github className="w-8" />
|
||||
</a>
|
||||
</Link>
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
|
||||
const PageLayout: React.VoidFunctionComponent<PageLayoutProps> = ({
|
||||
children,
|
||||
}) => {
|
||||
const breakpoint = useBreakpoint();
|
||||
return (
|
||||
<div className="bg-pattern h-full overflow-x-hidden">
|
||||
<Head>
|
||||
<title>Rallly - Support</title>
|
||||
</Head>
|
||||
<div className="">
|
||||
<div className="py-8 flex items-center px-8 max-w-7xl mx-auto">
|
||||
<div className="grow">
|
||||
<div className="inline-block relative">
|
||||
<Link href="/">
|
||||
<a>
|
||||
<Logo className="w-40 text-indigo-500" alt="Rallly" />
|
||||
</a>
|
||||
</Link>
|
||||
<span className="absolute transition-colors text-sm text-slate-400 -bottom-6 right-0">
|
||||
Yes—with 3 <em>L</em>s
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<Menu className="hidden md:flex space-x-8 items-center" />
|
||||
{breakpoint === "sm" ? (
|
||||
<Popover
|
||||
placement="left-start"
|
||||
trigger={
|
||||
<button className="text-gray-400 hover:text-indigo-500 hover:underline-offset-2 hover:no-underline transition-colors">
|
||||
<DotsVertical className="w-5" />
|
||||
</button>
|
||||
}
|
||||
>
|
||||
<Menu className="flex flex-col space-y-2" />
|
||||
</Popover>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div className="md:min-h-[calc(100vh-460px)]">{children}</div>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PageLayout;
|
83
components/page-layout/footer.tsx
Normal file
|
@ -0,0 +1,83 @@
|
|||
import Link from "next/link";
|
||||
import * as React from "react";
|
||||
import GitHubButton from "react-github-btn";
|
||||
import { Trans, useTranslation } from "next-i18next";
|
||||
import Logo from "../../public/logo.svg";
|
||||
|
||||
const Footer: React.VoidFunctionComponent = () => {
|
||||
const { t } = useTranslation("homepage");
|
||||
return (
|
||||
<div className="bg-gradient-to-b from-transparent via-slate-50 to-slate-100">
|
||||
<div className="py-24 px-8 mx-auto max-w-7xl grid grid-cols-12 gap-8">
|
||||
<div className="col-span-12 md:col-span-4">
|
||||
<Logo className="w-32 text-slate-300 mb-8" />
|
||||
</div>
|
||||
<div className="col-span-6 md:col-span-2">
|
||||
<div className="font-medium mb-4">Links</div>
|
||||
<ul className="footer-menu">
|
||||
<li>
|
||||
<a href="https://github.com/lukevella/Rallly/discussions">
|
||||
Forum
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<Link href="/blog">
|
||||
<a>Blog</a>
|
||||
</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link href="/support">
|
||||
<a>Support</a>
|
||||
</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link href="/privacy-policy">
|
||||
<a>Privacy Policy</a>
|
||||
</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div className="col-span-6 md:col-span-2">
|
||||
<div className="font-medium mb-4">Follow</div>
|
||||
<ul className="footer-menu">
|
||||
<li>
|
||||
<a href="https://github.com/lukevella/Rallly">Github</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://twitter.com/ralllyco">Twitter</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div className="col-span-12 md:col-span-3">
|
||||
<div className="font-medium mb-4">Project</div>
|
||||
<p className="text-sm text-slate-500">
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey="footerCredit"
|
||||
components={{ a: <a href="https://twitter.com/imlukevella" /> }}
|
||||
/>
|
||||
</p>
|
||||
<div className="flex space-x-3">
|
||||
<GitHubButton
|
||||
href="https://github.com/lukevella/Rallly"
|
||||
data-icon="octicon-star"
|
||||
aria-label="Star lukevella/Rallly on GitHub"
|
||||
data-show-count={true}
|
||||
>
|
||||
Star
|
||||
</GitHubButton>
|
||||
<GitHubButton
|
||||
href="https://github.com/sponsors/lukevella"
|
||||
data-icon="octicon-heart"
|
||||
aria-label="Sponsor @lukevella on GitHub"
|
||||
>
|
||||
Sponsor this project
|
||||
</GitHubButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Footer;
|
1
components/poll/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from "./poll";
|
58
components/poll/legacy-poll-notice.tsx
Normal file
|
@ -0,0 +1,58 @@
|
|||
import Speakerphone from "@/components/icons/speakerphone.svg";
|
||||
import Cookies from "js-cookie";
|
||||
import * as React from "react";
|
||||
|
||||
const cookieName = "legacy-poll-notice";
|
||||
|
||||
const LegacyPollNotice: React.VoidFunctionComponent<{ show?: boolean }> = ({
|
||||
show,
|
||||
}) => {
|
||||
const [visible, setVisible] = React.useState(show);
|
||||
|
||||
if (!visible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const didSeeLegacyPollNotice = !!Cookies.get(cookieName);
|
||||
|
||||
if (didSeeLegacyPollNotice) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const setCookie = () => {
|
||||
setVisible(false);
|
||||
Cookies.set(cookieName, "1", {
|
||||
expires: 60,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="md:flex md:items-center space-y-3 md:space-y-0 text-sm shadow-sm rounded-lg mb-4 border md:space-x-4 p-2 bg-yellow-200 text-yellow-700">
|
||||
<div className="flex space-x-3 md:grow md:items-center">
|
||||
<div className="bg-yellow-400 w-9 h-9 p-2 rounded-lg">
|
||||
<Speakerphone className="w-5" />
|
||||
</div>
|
||||
<div className="grow">
|
||||
Notice anything different? We've announced a new version release.
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex space-x-3 ml-12">
|
||||
<a
|
||||
onClick={() => setCookie()}
|
||||
className="btn-default border-0"
|
||||
href="https://blog.rallly.co/posts/new-version-announcment"
|
||||
>
|
||||
Read more
|
||||
</a>
|
||||
<button
|
||||
onClick={() => setCookie()}
|
||||
className="py-2 px-3 transition-colors bg-yellow-300 rounded-lg active:bg-yellow-400"
|
||||
>
|
||||
Hide
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default LegacyPollNotice;
|
210
components/poll/manage-poll.tsx
Normal file
|
@ -0,0 +1,210 @@
|
|||
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 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 { Placement } from "@popperjs/core";
|
||||
|
||||
const PollOptionsForm = React.lazy(() => import("../forms/poll-options-form"));
|
||||
|
||||
const ManagePoll: React.VoidFunctionComponent<{
|
||||
targetTimeZone: string;
|
||||
placement?: Placement;
|
||||
}> = ({ targetTimeZone, placement }) => {
|
||||
const { t } = useTranslation("app");
|
||||
const poll = usePoll();
|
||||
|
||||
const { mutate: updatePollMutation, isLoading: isUpdating } =
|
||||
useUpdatePollMutation();
|
||||
const [
|
||||
changeOptionsModalContextHolder,
|
||||
openChangeOptionsModal,
|
||||
closeChangeOptionsModal,
|
||||
] = useModal({
|
||||
okText: "Save",
|
||||
okButtonProps: {
|
||||
form: "pollOptions",
|
||||
htmlType: "submit",
|
||||
loading: isUpdating,
|
||||
},
|
||||
cancelText: "Cancel",
|
||||
content: (
|
||||
<React.Suspense fallback={null}>
|
||||
<PollOptionsForm
|
||||
name="pollOptions"
|
||||
title={poll.title}
|
||||
defaultValues={{
|
||||
navigationDate: poll.options[0].value.split("/")[0],
|
||||
options: poll.options.map((option) => {
|
||||
const [start, end] = option.value.split("/");
|
||||
return end
|
||||
? {
|
||||
type: "timeSlot",
|
||||
start,
|
||||
end,
|
||||
}
|
||||
: {
|
||||
type: "date",
|
||||
date: start,
|
||||
};
|
||||
}),
|
||||
timeZone: poll.timeZone ?? "",
|
||||
}}
|
||||
onSubmit={(data) => {
|
||||
const encodedOptions = data.options.map(encodeDateOption);
|
||||
const optionsToDelete = poll.options
|
||||
.filter((option) => {
|
||||
return !encodedOptions.includes(option.value);
|
||||
})
|
||||
.map((option) => option.id);
|
||||
|
||||
const optionsToAdd = encodedOptions.filter(
|
||||
(encodedOption) =>
|
||||
!poll.options.find((o) => o.value === encodedOption),
|
||||
);
|
||||
updatePollMutation(
|
||||
{
|
||||
timeZone: data.timeZone,
|
||||
optionsToDelete,
|
||||
optionsToAdd,
|
||||
},
|
||||
{
|
||||
onSuccess: () => closeChangeOptionsModal(),
|
||||
},
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</React.Suspense>
|
||||
),
|
||||
});
|
||||
|
||||
const [
|
||||
changePollDetailsModalContextHolder,
|
||||
openChangePollDetailsModa,
|
||||
closePollDetailsModal,
|
||||
] = useModal({
|
||||
okText: "Save changes",
|
||||
okButtonProps: {
|
||||
form: "updateDetails",
|
||||
loading: isUpdating,
|
||||
htmlType: "submit",
|
||||
},
|
||||
cancelText: "Cancel",
|
||||
content: (
|
||||
<PollDetailsForm
|
||||
name="updateDetails"
|
||||
defaultValues={{
|
||||
title: poll.title,
|
||||
location: poll.location ?? "",
|
||||
description: poll.description ?? "",
|
||||
}}
|
||||
className="p-4"
|
||||
onSubmit={(data) => {
|
||||
//submit
|
||||
updatePollMutation(data, { onSuccess: closePollDetailsModal });
|
||||
}}
|
||||
/>
|
||||
),
|
||||
});
|
||||
return (
|
||||
<>
|
||||
{changeOptionsModalContextHolder}
|
||||
{changePollDetailsModalContextHolder}
|
||||
<Dropdown
|
||||
placement={placement}
|
||||
trigger={<Button icon={<Cog />}>Manage</Button>}
|
||||
>
|
||||
<DropdownItem
|
||||
icon={Pencil}
|
||||
label="Edit details"
|
||||
onClick={openChangePollDetailsModa}
|
||||
/>
|
||||
<DropdownItem
|
||||
icon={Table}
|
||||
label="Edit options"
|
||||
onClick={openChangeOptionsModal}
|
||||
/>
|
||||
<DropdownItem
|
||||
icon={Save}
|
||||
label="Export to CSV"
|
||||
onClick={() => {
|
||||
const header = [
|
||||
t("participantCount", {
|
||||
count: poll.participants.length,
|
||||
}),
|
||||
...poll.options.map((option) => {
|
||||
const decodedOption = decodeDateOption(
|
||||
option.value,
|
||||
poll.timeZone,
|
||||
targetTimeZone,
|
||||
);
|
||||
const day = `${decodedOption.dow} ${decodedOption.day} ${decodedOption.month}`;
|
||||
return decodedOption.type === "date"
|
||||
? day
|
||||
: `${day} ${decodedOption.startTime} - ${decodedOption.endTime}`;
|
||||
}),
|
||||
].join(",");
|
||||
const rows = poll.participants.map((participant) => {
|
||||
return [
|
||||
participant.name,
|
||||
...poll.options.map((option) => {
|
||||
if (
|
||||
participant.votes.some((vote) => {
|
||||
return vote.optionId === option.id;
|
||||
})
|
||||
) {
|
||||
return "Yes";
|
||||
}
|
||||
return "No";
|
||||
}),
|
||||
].join(",");
|
||||
});
|
||||
const csv = `data:text/csv;charset=utf-8,${[header, ...rows].join(
|
||||
"\r\n",
|
||||
)}`;
|
||||
|
||||
const encodedCsv = encodeURI(csv);
|
||||
var link = document.createElement("a");
|
||||
link.setAttribute("href", encodedCsv);
|
||||
link.setAttribute(
|
||||
"download",
|
||||
`${poll.title.replace(/\s/g, "_")}-${format(
|
||||
Date.now(),
|
||||
"yyyyMMddhhmm",
|
||||
)}`,
|
||||
);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}}
|
||||
/>
|
||||
{poll.closed ? (
|
||||
<DropdownItem
|
||||
icon={LockOpen}
|
||||
label="Unlock poll"
|
||||
onClick={() => updatePollMutation({ closed: false })}
|
||||
/>
|
||||
) : (
|
||||
<DropdownItem
|
||||
icon={LockClosed}
|
||||
label="Lock poll"
|
||||
onClick={() => updatePollMutation({ closed: true })}
|
||||
/>
|
||||
)}
|
||||
</Dropdown>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ManagePoll;
|
1
components/poll/mobile-poll/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from "./mobile-poll";
|
334
components/poll/mobile-poll/mobile-poll.tsx
Normal file
|
@ -0,0 +1,334 @@
|
|||
import { usePoll } from "@/components/use-poll";
|
||||
import { Listbox } from "@headlessui/react";
|
||||
import { Participant, Vote } from "@prisma/client";
|
||||
import clsx from "clsx";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import * as React from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { decodeDateOption } from "../../../utils/date-time-utils";
|
||||
import { requiredString } from "../../../utils/form-validation";
|
||||
import Button from "../../button";
|
||||
import DateCard from "../../date-card";
|
||||
import ChevronDown from "../../icons/chevron-down.svg";
|
||||
import Pencil from "../../icons/pencil.svg";
|
||||
import PlusCircle from "../../icons/plus-circle.svg";
|
||||
import Save from "../../icons/save.svg";
|
||||
import Trash from "../../icons/trash.svg";
|
||||
import { styleMenuItem } from "../../menu-styles";
|
||||
import NameInput from "../../name-input";
|
||||
import TimeZonePicker from "../../time-zone-picker";
|
||||
import { TransitionPopInOut } from "../../transitions";
|
||||
import { useUserName } from "../../user-name-context";
|
||||
import {
|
||||
useAddParticipantMutation,
|
||||
useUpdateParticipantMutation,
|
||||
} from "../mutations";
|
||||
import TimeRange from "../time-range";
|
||||
import { ParticipantForm, PollProps } from "../types";
|
||||
import { useDeleteParticipantModal } from "../use-delete-participant-modal";
|
||||
import UserAvater from "../user-avatar";
|
||||
import VoteIcon from "../vote-icon";
|
||||
|
||||
const MobilePoll: React.VoidFunctionComponent<PollProps> = ({
|
||||
pollId,
|
||||
timeZone,
|
||||
options,
|
||||
participants,
|
||||
highScore,
|
||||
targetTimeZone,
|
||||
onChangeTargetTimeZone,
|
||||
role,
|
||||
}) => {
|
||||
const [, setUserName] = useUserName();
|
||||
|
||||
const participantById = participants.reduce<
|
||||
Record<string, Participant & { votes: Vote[] }>
|
||||
>((acc, curr) => {
|
||||
acc[curr.id] = { ...curr };
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const { register, setValue, reset, handleSubmit, control, formState } =
|
||||
useForm<ParticipantForm>({
|
||||
defaultValues: {
|
||||
name: "",
|
||||
votes: [],
|
||||
},
|
||||
});
|
||||
const [selectedParticipantId, setSelectedParticipantId] =
|
||||
React.useState<string>();
|
||||
|
||||
const selectedParticipant = selectedParticipantId
|
||||
? participantById[selectedParticipantId]
|
||||
: undefined;
|
||||
|
||||
const selectedParticipantVotedOption = selectedParticipant
|
||||
? selectedParticipant.votes.map((vote) => vote.optionId)
|
||||
: undefined;
|
||||
|
||||
const [mode, setMode] = React.useState<"edit" | "default">(() =>
|
||||
participants.length > 0 ? "default" : "edit",
|
||||
);
|
||||
|
||||
const { t } = useTranslation("app");
|
||||
|
||||
const { mutate: updateParticipantMutation } =
|
||||
useUpdateParticipantMutation(pollId);
|
||||
|
||||
const { mutate: addParticipantMutation } = useAddParticipantMutation(pollId);
|
||||
const [deleteParticipantModal, confirmDeleteParticipant] =
|
||||
useDeleteParticipantModal(pollId, selectedParticipantId ?? ""); // TODO (Luke Vella) [2022-03-14]: Figure out a better way to deal with these modals
|
||||
|
||||
// This hack is necessary because when there is only one checkbox,
|
||||
// react-hook-form does not know to format the value into an array.
|
||||
// See: https://github.com/react-hook-form/react-hook-form/issues/7834
|
||||
const checkboxGroupHack = (
|
||||
<input type="checkbox" className="hidden" {...register("votes")} />
|
||||
);
|
||||
|
||||
const poll = usePoll();
|
||||
|
||||
return (
|
||||
<form
|
||||
className="border-t border-b shadow-sm bg-white"
|
||||
onSubmit={handleSubmit((data) => {
|
||||
return new Promise<ParticipantForm>((resolve, reject) => {
|
||||
if (selectedParticipant) {
|
||||
updateParticipantMutation(
|
||||
{
|
||||
participantId: selectedParticipant.id,
|
||||
pollId,
|
||||
...data,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
setMode("default");
|
||||
resolve(data);
|
||||
},
|
||||
onError: reject,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
addParticipantMutation(data, {
|
||||
onSuccess: (newParticipant) => {
|
||||
setMode("default");
|
||||
setSelectedParticipantId(newParticipant.id);
|
||||
resolve(data);
|
||||
},
|
||||
onError: reject,
|
||||
});
|
||||
}
|
||||
});
|
||||
})}
|
||||
>
|
||||
{checkboxGroupHack}
|
||||
<div className="sticky top-0 px-4 py-2 space-y-2 flex flex-col border-b z-30 bg-gray-50">
|
||||
{mode === "default" ? (
|
||||
<div className="flex space-x-3">
|
||||
<Listbox
|
||||
value={selectedParticipantId}
|
||||
onChange={setSelectedParticipantId}
|
||||
>
|
||||
<div className="menu grow">
|
||||
<Listbox.Button className="btn-default w-full text-left">
|
||||
<div className="grow">
|
||||
{selectedParticipant ? (
|
||||
<div className="flex space-x-2 items-center">
|
||||
<UserAvater name={selectedParticipant.name} />
|
||||
<span>{selectedParticipant.name}</span>
|
||||
</div>
|
||||
) : (
|
||||
t("participantCount", { count: participants.length })
|
||||
)}
|
||||
</div>
|
||||
<ChevronDown className="h-5" />
|
||||
</Listbox.Button>
|
||||
<TransitionPopInOut>
|
||||
<Listbox.Options className="menu-items w-full">
|
||||
<Listbox.Option value={undefined} className={styleMenuItem}>
|
||||
Show all
|
||||
</Listbox.Option>
|
||||
{participants.map((participant) => (
|
||||
<Listbox.Option
|
||||
key={participant.id}
|
||||
value={participant.id}
|
||||
className={styleMenuItem}
|
||||
>
|
||||
<div className="flex space-x-2 items-center">
|
||||
<UserAvater name={participant.name} />
|
||||
<span>{participant.name}</span>
|
||||
</div>
|
||||
</Listbox.Option>
|
||||
))}
|
||||
</Listbox.Options>
|
||||
</TransitionPopInOut>
|
||||
</div>
|
||||
</Listbox>
|
||||
{!poll.closed ? (
|
||||
selectedParticipant ? (
|
||||
<div className="flex space-x-3">
|
||||
<Button
|
||||
icon={<Pencil />}
|
||||
onClick={() => {
|
||||
setMode("edit");
|
||||
setValue("name", selectedParticipant.name);
|
||||
setValue(
|
||||
"votes",
|
||||
selectedParticipant.votes.map((vote) => vote.optionId),
|
||||
);
|
||||
}}
|
||||
>
|
||||
Edit
|
||||
</Button>
|
||||
{role === "admin" ? (
|
||||
<Button
|
||||
icon={<Trash />}
|
||||
type="danger"
|
||||
onClick={confirmDeleteParticipant}
|
||||
/>
|
||||
) : null}
|
||||
{deleteParticipantModal}
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusCircle />}
|
||||
onClick={() => {
|
||||
reset();
|
||||
setUserName("");
|
||||
setMode("edit");
|
||||
}}
|
||||
>
|
||||
New
|
||||
</Button>
|
||||
)
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{mode === "edit" ? (
|
||||
<Controller
|
||||
name="name"
|
||||
control={control}
|
||||
rules={{ validate: requiredString }}
|
||||
render={({ field }) => (
|
||||
<NameInput
|
||||
disabled={formState.isSubmitting}
|
||||
autoFocus={!selectedParticipant}
|
||||
className="w-full"
|
||||
{...field}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
) : null}
|
||||
{timeZone ? (
|
||||
<TimeZonePicker
|
||||
value={targetTimeZone}
|
||||
onChange={onChangeTargetTimeZone}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="divide-y">
|
||||
{options.map((option) => {
|
||||
const parsedOption = decodeDateOption(
|
||||
option.value,
|
||||
timeZone,
|
||||
targetTimeZone,
|
||||
);
|
||||
const numVotes = option.votes.length;
|
||||
return (
|
||||
<div
|
||||
key={option.id}
|
||||
className="px-4 py-2 flex items-center space-x-4"
|
||||
>
|
||||
<div>
|
||||
<DateCard
|
||||
day={parsedOption.day}
|
||||
dow={parsedOption.dow}
|
||||
month={parsedOption.month}
|
||||
/>
|
||||
</div>
|
||||
{parsedOption.type === "timeSlot" ? (
|
||||
<TimeRange
|
||||
startTime={parsedOption.startTime}
|
||||
endTime={parsedOption.endTime}
|
||||
className="shrink-0"
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<div className="grow space-y-1 items-center">
|
||||
<div>
|
||||
<span
|
||||
className={clsx(
|
||||
"inline-block px-2 leading-relaxed border rounded-full text-xs",
|
||||
{
|
||||
"border-slate-200": numVotes !== highScore,
|
||||
"border-rose-500 text-rose-500": numVotes === highScore,
|
||||
},
|
||||
)}
|
||||
>
|
||||
{t("voteCount", { count: numVotes })}
|
||||
</span>
|
||||
</div>
|
||||
{option.votes.length ? (
|
||||
<div className="-space-x-1">
|
||||
{option.votes
|
||||
.slice(0, option.votes.length <= 6 ? 6 : 5)
|
||||
.map((vote) => {
|
||||
const participant = participantById[vote.participantId];
|
||||
return (
|
||||
<UserAvater
|
||||
key={vote.id}
|
||||
className="ring-1 ring-white"
|
||||
name={participant.name}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{option.votes.length > 6 ? (
|
||||
<span className="inline-flex ring-1 ring-white items-center justify-center rounded-full font-medium bg-slate-100 text-xs px-1 h-5">
|
||||
+{option.votes.length - 5}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="w-12 items-center justify-center h-14 flex">
|
||||
{mode === "edit" ? (
|
||||
<input
|
||||
type="checkbox"
|
||||
className="checkbox"
|
||||
value={option.id}
|
||||
{...register("votes")}
|
||||
/>
|
||||
) : selectedParticipantVotedOption ? (
|
||||
selectedParticipantVotedOption.includes(option.id) ? (
|
||||
<VoteIcon type="yes" />
|
||||
) : (
|
||||
<VoteIcon type="no" />
|
||||
)
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{mode === "edit" ? (
|
||||
<div className="p-2 border-t flex space-x-3">
|
||||
<Button className="grow" onClick={() => setMode("default")}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
icon={<Save />}
|
||||
htmlType="submit"
|
||||
className="grow"
|
||||
type="primary"
|
||||
loading={formState.isSubmitting}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
export default MobilePoll;
|
115
components/poll/mutations.ts
Normal file
|
@ -0,0 +1,115 @@
|
|||
import { updatePoll, UpdatePollPayload } from "api-client/update-poll";
|
||||
import { usePlausible } from "next-plausible";
|
||||
import { useMutation, useQuery, useQueryClient } from "react-query";
|
||||
import { addParticipant } from "../../api-client/add-participant";
|
||||
import {
|
||||
deleteParticipant,
|
||||
DeleteParticipantPayload,
|
||||
} from "../../api-client/delete-participant";
|
||||
import { GetPollResponse } from "../../api-client/get-poll";
|
||||
import {
|
||||
updateParticipant,
|
||||
UpdateParticipantPayload,
|
||||
} from "../../api-client/update-participant";
|
||||
import { usePoll } from "../use-poll";
|
||||
import { useUserName } from "../user-name-context";
|
||||
import { ParticipantForm } from "./types";
|
||||
|
||||
export const useAddParticipantMutation = (pollId: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
const [, setUserName] = useUserName();
|
||||
const plausible = usePlausible();
|
||||
return useMutation(
|
||||
(payload: ParticipantForm) =>
|
||||
addParticipant({
|
||||
pollId,
|
||||
name: payload.name.trim(),
|
||||
votes: payload.votes,
|
||||
}),
|
||||
{
|
||||
onSuccess: (participant, { name }) => {
|
||||
plausible("Add participant");
|
||||
setUserName(name);
|
||||
queryClient.setQueryData<GetPollResponse>(
|
||||
["getPoll", pollId],
|
||||
(poll) => {
|
||||
if (!poll) {
|
||||
throw new Error(
|
||||
"Tried to update poll but no result found in query cache",
|
||||
);
|
||||
}
|
||||
poll.participants = [participant, ...poll.participants];
|
||||
participant.votes.forEach((vote) => {
|
||||
const votedOption = poll.options.find(
|
||||
(option) => option.id === vote.optionId,
|
||||
);
|
||||
votedOption?.votes.push(vote);
|
||||
});
|
||||
poll.options.forEach((option) => {
|
||||
participant.votes.some(({ optionId }) => optionId === option.id);
|
||||
});
|
||||
return poll;
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const useUpdateParticipantMutation = (pollId: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
const [, setUserName] = useUserName();
|
||||
const plausible = usePlausible();
|
||||
return useMutation(
|
||||
(payload: UpdateParticipantPayload) =>
|
||||
updateParticipant({
|
||||
pollId,
|
||||
participantId: payload.participantId,
|
||||
name: payload.name.trim(),
|
||||
votes: payload.votes,
|
||||
}),
|
||||
{
|
||||
onMutate: ({ name }) => {
|
||||
setUserName(name);
|
||||
},
|
||||
onSuccess: () => {
|
||||
plausible("Update participant");
|
||||
},
|
||||
onSettled: () => {
|
||||
queryClient.invalidateQueries(["getPoll", pollId]);
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const useDeleteParticipantMutation = (pollId: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
const plausible = usePlausible();
|
||||
return useMutation(
|
||||
(payload: DeleteParticipantPayload) => deleteParticipant(payload),
|
||||
{
|
||||
onSuccess: () => {
|
||||
plausible("Remove participant");
|
||||
},
|
||||
onSettled: () => {
|
||||
queryClient.invalidateQueries(["getPoll", pollId]);
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const useUpdatePollMutation = () => {
|
||||
const poll = usePoll();
|
||||
const plausible = usePlausible();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(payload: UpdatePollPayload) => updatePoll(poll.urlId, payload),
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
queryClient.setQueryData(["getPoll", poll.urlId], data);
|
||||
plausible("Updated poll");
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
82
components/poll/notifications-toggle.tsx
Normal file
|
@ -0,0 +1,82 @@
|
|||
import * as React from "react";
|
||||
import Tooltip from "../tooltip";
|
||||
import { usePoll } from "../use-poll";
|
||||
import { Trans, useTranslation } from "next-i18next";
|
||||
import Button from "@/components/button";
|
||||
import Bell from "@/components/icons/bell.svg";
|
||||
import BellCrossed from "@/components/icons/bell-crossed.svg";
|
||||
import { useUpdatePollMutation } from "./mutations";
|
||||
import { usePlausible } from "next-plausible";
|
||||
|
||||
export interface NotificationsToggleProps {}
|
||||
|
||||
const NotificationsToggle: React.VoidFunctionComponent<NotificationsToggleProps> =
|
||||
() => {
|
||||
const poll = usePoll();
|
||||
const { t } = useTranslation("app");
|
||||
const [isUpdatingNotifications, setIsUpdatingNotifications] =
|
||||
React.useState(false);
|
||||
|
||||
const { mutate: updatePollMutation } = useUpdatePollMutation();
|
||||
|
||||
const plausible = usePlausible();
|
||||
return (
|
||||
<Tooltip
|
||||
content={
|
||||
poll.verified ? (
|
||||
poll.notifications ? (
|
||||
<div>
|
||||
<div className="font-medium text-indigo-300">
|
||||
Notifications are on
|
||||
</div>
|
||||
<div className="max-w-sm">
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey="notificationsOnDescription"
|
||||
values={{
|
||||
email: poll.user.email,
|
||||
}}
|
||||
components={{
|
||||
b: <span className="email" />,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
"Notifications are off"
|
||||
)
|
||||
) : (
|
||||
"You need to verify your email to turn on notifications"
|
||||
)
|
||||
}
|
||||
>
|
||||
<Button
|
||||
loading={isUpdatingNotifications}
|
||||
icon={
|
||||
poll.verified && poll.notifications ? <Bell /> : <BellCrossed />
|
||||
}
|
||||
disabled={!poll.verified}
|
||||
onClick={() => {
|
||||
setIsUpdatingNotifications(true);
|
||||
updatePollMutation(
|
||||
{
|
||||
notifications: !poll.notifications,
|
||||
},
|
||||
{
|
||||
onSuccess: ({ notifications }) => {
|
||||
plausible(
|
||||
notifications
|
||||
? "Turned notifications on"
|
||||
: "Turned notifications off",
|
||||
);
|
||||
setIsUpdatingNotifications(false);
|
||||
},
|
||||
},
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
export default NotificationsToggle;
|