Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: limit email sends #609

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion components/datarooms/add-viewer-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";

import { useAnalytics } from "@/lib/analytics";
import { usePlan } from "@/lib/swr/use-billing";

export function AddViewerModal({
dataroomId,
Expand All @@ -37,6 +38,8 @@ export function AddViewerModal({
const [loading, setLoading] = useState<boolean>(false);
const teamInfo = useTeam();
const analytics = useAnalytics();
const { trial } = usePlan();
const isTrial = !!trial;

// Email validation regex pattern
const validateEmail = (email: string) => {
Expand Down Expand Up @@ -116,6 +119,20 @@ export function AddViewerModal({

if (emails.length === 0) return;

if (isTrial) {
toast.error(
"You are on a trial plan. You cannot send email invitations to prevent spamming.",
);
return;
}

if (emails.length > 5) {
toast.error(
"You can only send invitations to a maximum of 5 emails at a time.",
);
return;
}

setLoading(true);

// POST request with multiple emails
Expand Down Expand Up @@ -170,7 +187,7 @@ export function AddViewerModal({
<Label htmlFor="email" className="opacity-80">
Emails
</Label>
<div className="flex flex-wrap gap-2 py-2 text-sm">
<div className="flex flex-wrap gap-2 py-2 text-sm">
{emails.map((email, index) => (
<div
key={index}
Expand Down