2022-03-09 22:56:05 +00:00
|
|
|
import slugify from "@calcom/lib/slugify";
|
2022-07-01 17:19:52 +00:00
|
|
|
import { WEBSITE_URL } from "@calcom/lib/constants";
|
2021-09-28 08:57:30 +00:00
|
|
|
|
2022-03-24 17:45:56 +00:00
|
|
|
export type ResponseUsernameApi = {
|
2022-03-09 22:56:05 +00:00
|
|
|
available: boolean;
|
|
|
|
premium: boolean;
|
|
|
|
message?: string;
|
|
|
|
suggestion?: string;
|
2022-03-24 17:45:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export async function checkPremiumUsername(_username: string): Promise<ResponseUsernameApi> {
|
2021-09-28 08:57:30 +00:00
|
|
|
const username = slugify(_username);
|
2022-07-01 17:19:52 +00:00
|
|
|
const response = await fetch(`${ WEBSITE_URL }/api/username`, {
|
2021-09-28 08:57:30 +00:00
|
|
|
credentials: "include",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ username }),
|
|
|
|
method: "POST",
|
|
|
|
mode: "cors",
|
|
|
|
});
|
|
|
|
|
|
|
|
const json = await response.json();
|
2022-03-09 22:56:05 +00:00
|
|
|
return json;
|
2021-09-28 08:57:30 +00:00
|
|
|
}
|