Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion components/datarooms/add-dataroom-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useState } from "react";
import { useTeam } from "@/context/team-context";
import { toast } from "sonner";
import { mutate } from "swr";
import { z } from "zod";

import { Button } from "@/components/ui/button";
import {
Expand Down Expand Up @@ -41,12 +42,20 @@ export function AddDataroomModal({
const teamInfo = useTeam();
const { plan } = usePlan();
const analytics = useAnalytics();
const dataroomSchema = z.object({
name: z.string().min(3, {
message: "Dataroom name is required. Please enter a valid name.",
}),
});

const handleSubmit = async (event: any) => {
event.preventDefault();
event.stopPropagation();

if (dataroomName == "") return;
const validation = dataroomSchema.safeParse({ name: dataroomName });
if (!validation.success) {
return toast.error(validation.error.errors[0].message);
}

setLoading(true);

Expand Down
13 changes: 12 additions & 1 deletion components/datarooms/groups/add-group-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState } from "react";
import { useTeam } from "@/context/team-context";
import { toast } from "sonner";
import { mutate } from "swr";
import { z } from "zod";

import { Button } from "@/components/ui/button";
import {
Expand Down Expand Up @@ -36,12 +37,22 @@ export function AddGroupModal({

const teamInfo = useTeam();
const analytics = useAnalytics();
const addGroupSchema = z.object({
name: z
.string()
.min(3, {
message: "Group name is required. Please enter a valid name.",
}),
});

const handleSubmit = async (event: any) => {
event.preventDefault();
event.stopPropagation();

if (groupName == "") return;
const validation = addGroupSchema.safeParse({ name: groupName });
if (!validation.success) {
return toast.error(validation.error.errors[0].message);
}

setLoading(true);

Expand Down
19 changes: 13 additions & 6 deletions components/domains/add-domain-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from "react";

import { useTeam } from "@/context/team-context";
import { toast } from "sonner";
import { z } from "zod";

import { Button } from "@/components/ui/button";
import {
Expand Down Expand Up @@ -42,17 +43,23 @@ export function AddDomainModal({
const { plan } = usePlan();
const { limits } = useLimits();
const analytics = useAnalytics();
const addDomainSchema = z.object({
name: z
.string()
.min(3, { message: "Domain is required. Please enter a valid domain." })
// Add validation for papermark
.refine((name) => !name.toLowerCase().includes("papermark"), {
message: "Domain cannot contain 'papermark'",
}),
});

const handleSubmit = async (event: any) => {
event.preventDefault();
event.stopPropagation();

if (domain == "") return;

// Add validation for papermark
if (domain.toLowerCase().includes("papermark")) {
toast.error("Domain cannot contain 'papermark'");
return;
const validation = addDomainSchema.safeParse({ name: domain });
if (!validation.success) {
return toast.error(validation.error.errors[0].message);
}

setLoading(true);
Expand Down
12 changes: 11 additions & 1 deletion components/folders/add-folder-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTeam } from "@/context/team-context";
import { Folder } from "@prisma/client";
import { toast } from "sonner";
import { mutate } from "swr";
import { z } from "zod";

import { Button } from "@/components/ui/button";
import {
Expand Down Expand Up @@ -51,12 +52,21 @@ export function AddFolderModal({

/** current folder name */
const currentFolderPath = router.query.name as string[] | undefined;
const addFolderSchema = z.object({
name: z.string().min(3, {
message: "Folder name is required. Please enter a valid name.",
}),
});

const handleSubmit = async (event: any) => {
event.preventDefault();
event.stopPropagation();

if (folderName == "") return;
const validation = addFolderSchema.safeParse({ name: folderName });
if (!validation.success) {
toast.error(validation.error.errors[0].message);
return;
}

setLoading(true);
const endpointTargetType =
Expand Down
11 changes: 10 additions & 1 deletion components/folders/edit-folder-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useState } from "react";
import { useTeam } from "@/context/team-context";
import { toast } from "sonner";
import { mutate } from "swr";
import { z } from "zod";

import { Button } from "@/components/ui/button";
import {
Expand Down Expand Up @@ -40,12 +41,20 @@ export function EditFolderModal({
const [loading, setLoading] = useState<boolean>(false);

const teamInfo = useTeam();
const editFolderSchema = z.object({
name: z.string().min(3, {
message: "Folder name is required. Please enter a valid name.",
}),
});

const handleSubmit = async (event: any) => {
event.preventDefault();
event.stopPropagation();

if (folderName == "") return;
const validation = editFolderSchema.safeParse({ name: folderName });
if (!validation.success) {
return toast.error(validation.error.errors[0].message);
}

setLoading(true);
const endpointTargetType =
Expand Down
11 changes: 10 additions & 1 deletion components/teams/add-team-member-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useState } from "react";
import { useTeam } from "@/context/team-context";
import { toast } from "sonner";
import { mutate } from "swr";
import { z } from "zod";

import { Button } from "@/components/ui/button";
import {
Expand Down Expand Up @@ -34,12 +35,20 @@ export function AddTeamMembers({
const [loading, setLoading] = useState<boolean>(false);
const teamInfo = useTeam();
const analytics = useAnalytics();
const emailSchema = z
.string()
.min(3, { message: "Email name is required." })
.email({ message: "Please enter a valid email." });

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
event.stopPropagation();

if (!email) return;
const validation = emailSchema.safeParse(email);
if (!validation.success) {
toast.error(validation.error.errors[0].message);
return;
}

setLoading(true);
const response = await fetch(
Expand Down