feat: widget id

This commit is contained in:
Tristan Yang
2024-06-24 18:34:05 +08:00
parent 6997c3173b
commit 6bc2d1730b
8 changed files with 40 additions and 27 deletions
+5
View File
@@ -88,6 +88,11 @@ export default function Widget() {
</thead>
<tbody>
{[
{
paramKey: "id",
paramDefault: "-",
remarks: t("param_id")
},
{
paramKey: "host-id",
paramDefault: 1,
+1
View File
@@ -18,6 +18,7 @@ export interface User {
webhook_url?: string;
is_bot?: boolean;
log_id?: number;
widget_id?: string;
}
export type ContactAction = "add" | "remove" | "block" | "unblock";
export type ContactStatus = "added" | "blocked" | "";
+1 -1
View File
@@ -23,7 +23,7 @@ const randomText = () => (Math.random() + 1).toString(36).substring(7);
const Login = () => {
const { t } = useTranslation("widget");
const dispatch = useDispatch();
const { color, fgColor, from, autoReg, token } = useWidget();
const { color, fgColor, from, autoReg, token, id } = useWidget();
const { clientId } = useGoogleAuthConfig();
const { config: githubAuthConfig } = useGithubAuthConfig();
const [register, { isLoading, isSuccess, data, error }] = useRegisterMutation();
+3
View File
@@ -6,6 +6,7 @@ import { getContrastColor, isInIframe } from "../utils";
import { shallowEqual } from "react-redux";
const query = new URLSearchParams(location.search);
const id = decodeURIComponent(query.get("id") || "");
const welcome = decodeURIComponent(query.get("welcome") || "");
const autoReg = decodeURIComponent(query.get("autoReg") || "true") == "true";
const token = decodeURIComponent(query.get("token") || "");
@@ -14,6 +15,7 @@ const from = decodeURIComponent(query.get("from") || "widget.link");
const fgColor = getContrastColor(color);
const embed = isInIframe();
const WidgetContext = createContext({
id,
token,
autoReg,
color,
@@ -38,6 +40,7 @@ function WidgetProvider({ children }: { children: ReactNode }) {
return (
<WidgetContext.Provider
value={{
id,
token,
autoReg,
welcome,