mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* feat: dub refer embed * review fix * review fix * @dub/embed-core seems not needed * @dub/embed-core can stay in web * move refer page out of main-nav * update yarn lock * use loading.tsx --------- Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: hbjORbj <[email protected]>
72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
"use client";
|
|
|
|
import { DubEmbed } from "@dub/embed-react";
|
|
import { useTheme } from "next-themes";
|
|
import { useState, useEffect } from "react";
|
|
|
|
import { IS_DUB_REFERRALS_ENABLED } from "@calcom/lib/constants";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { showToast } from "@calcom/ui/components/toast";
|
|
|
|
const fetchReferralsToken = async () => {
|
|
try {
|
|
const response = await fetch("/api/user/referrals-token");
|
|
|
|
if (!response.ok) {
|
|
const { error } = await response.json();
|
|
showToast(error, "error");
|
|
return null;
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
return data.publicToken;
|
|
} catch (error) {
|
|
console.error("Error fetching referrals token:", error);
|
|
return null;
|
|
}
|
|
};
|
|
|
|
// The enabled referrals page implementation
|
|
export const DubReferralsPage = () => {
|
|
const [token, setToken] = useState<string | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
const { t } = useLocale();
|
|
const { resolvedTheme } = useTheme();
|
|
|
|
useEffect(() => {
|
|
const getToken = async () => {
|
|
try {
|
|
const publicToken = await fetchReferralsToken();
|
|
setToken(publicToken);
|
|
} catch (err) {
|
|
console.error("Error fetching referrals token:", err);
|
|
showToast(t("unexpected_error_try_again"), "error");
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
getToken();
|
|
}, []);
|
|
|
|
if (!IS_DUB_REFERRALS_ENABLED || !token) {
|
|
return null;
|
|
}
|
|
|
|
const theme = resolvedTheme === "dark" ? "dark" : "light";
|
|
|
|
return (
|
|
<DubEmbed
|
|
data="referrals"
|
|
token={token}
|
|
options={{
|
|
theme,
|
|
themeOptions: {
|
|
backgroundColor: `${theme === "dark" ? "#0F0F0F" : "#FFFFFF"}`,
|
|
},
|
|
}}
|
|
/>
|
|
);
|
|
};
|