Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix type error :lollipop:

Steven Tey11edc37fa31e
diff --git a/components/app/add-project-modal.tsx b/components/app/add-project-modal.tsx
index 674facf9c5..8426ad5c7f 100644
--- a/components/app/add-project-modal.tsx
+++ b/components/app/add-project-modal.tsx
@@ -28,8 +28,6 @@ function AddProjectModalHelper({
const [slugExistsError, setSlugExistsError] = useState(false);
const [generatingSlug, setGeneratingSlug] = useState(false);
- const [generatingTitle, setGeneratingTitle] = useState(false);
- const [buttonText, setButtonText] = useState("Add project");
const [saving, setSaving] = useState(false);
const [data, setData] = useState<{
@@ -98,15 +96,12 @@ function AddProjectModalHelper({
.then((res) => {
setSaving(false);
if (res.status === 200) {
- setButtonText("Saved!");
mutate(`/api/projects`);
- setShowAddProjectModal(false);
router.push(`/${slug}`);
}
})
.catch(() => {
setSaving(false);
- setButtonText("Add project");
setSlugExistsError(true);
});
}}
@@ -189,11 +184,10 @@ function AddProjectModalHelper({
<input
name="domain"
id="domain"
- type="url"
+ type="text"
required
className="border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500 block w-full rounded-md focus:outline-none sm:text-sm"
placeholder="dub.sh"
- pattern="(https?://)?.+"
value={domain}
onChange={(e) => {
setData({ ...data, domain: e.target.value });
@@ -211,7 +205,7 @@ function AddProjectModalHelper({
: "bg-black hover:bg-white hover:text-black border-black text-white"
} flex justify-center items-center w-full text-sm h-10 rounded-md border transition-all focus:outline-none`}
>
- {saving ? <LoadingDots color="#808080" /> : <p>{buttonText}</p>}
+ {saving ? <LoadingDots color="#808080" /> : <p>Add project</p>}
</button>
</form>
</div>
diff --git a/components/app/custom-domain/configurations.tsx b/components/app/custom-domain/configurations.tsx
index e95ffd2000..dbeb1677e9 100644
--- a/components/app/custom-domain/configurations.tsx
+++ b/components/app/custom-domain/configurations.tsx
@@ -1,7 +1,7 @@
import { useState } from "react";
import ConfigurationsPlaceholder from "./configurations-placeholder";
-function getVerificationError(verificationResponse) {
+function getVerificationError(verificationResponse: any) {
try {
const error = verificationResponse.error;
if (error.code === "missing_txt_record") {
@@ -13,14 +13,16 @@ function getVerificationError(verificationResponse) {
}
}
-const Configurations = ({ data }) => {
+const Configurations = ({ data }: { data: any }) => {
const [recordType, setRecordType] = useState("CNAME");
if (!data) {
return <ConfigurationsPlaceholder />;
}
if (!data.verified) {
- const txtVerification = data.verification.find((x) => x.type === "TXT");
+ const txtVerification = data.verification.find(
+ (x: any) => x.type === "TXT"
+ );
return (
<>
<div className="flex items-center space-x-3 my-3 px-2 sm:px-10">
diff --git a/pages/api/projects/index.ts b/pages/api/projects/index.ts
index 548fef69be..6288848454 100644
--- a/pages/api/projects/index.ts
+++ b/pages/api/projects/index.ts
@@ -29,21 +29,42 @@ export default async function handler(
return res.status(400).json({ error: "Missing name or slug or domain" });
}
- const project = await prisma.project.create({
- data: {
- name,
- slug,
- domain,
- users: {
- create: {
- userId: session.user.id,
- role: "owner",
+ try {
+ const project = await prisma.project.create({
+ data: {
+ name,
+ slug,
+ domain,
+ users: {
+ create: {
+ userId: session.user.id,
+ role: "owner",
+ },
},
},
- },
- });
-
- return res.status(200).json(project);
+ });
+ if (project?.domain) {
+ const response = await fetch(
+ `https://api.vercel.com/v9/projects/${process.env.VERCEL_PROJECT_ID}/domains?teamId=${process.env.VERCEL_TEAM_ID}`,
+ {
+ body: `{\n "name": "${project.domain}"\n}`,
+ headers: {
+ Authorization: `Bearer ${process.env.AUTH_BEARER_TOKEN}`,
+ "Content-Type": "application/json",
+ },
+ method: "POST",
+ }
+ );
+ const json = await response.json();
+ console.log(project, json);
+ return res.status(200).json({ project, domain: json });
+ }
+ return res.status(400).json({ error: "Project not created" });
+ } catch (error: any) {
+ if (error.code === "P2002") {
+ return res.status(400).json({ error: "Project slug already exists" });
+ }
+ }
} else {
res.setHeader("Allow", ["GET", "POST"]);
return res.status(405).json({ error: `Method ${req.method} Not Allowed` });