/* Copyright 2024 New Vector Ltd. Copyright 2024 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ import React, { useCallback, useEffect, useState } from "react"; import { ThreepidMedium } from "matrix-js-sdk/src/matrix"; import { Alert } from "@vector-im/compound-web"; import { _t } from "../../../languageHandler"; import InlineSpinner from "../elements/InlineSpinner"; import SettingsSubsection from "./shared/SettingsSubsection"; import { useMatrixClientContext } from "../../../contexts/MatrixClientContext"; import { ThirdPartyIdentifier } from "../../../AddThreepid"; import SettingsStore from "../../../settings/SettingsStore"; import { UIFeature } from "../../../settings/UIFeature"; import { AddRemoveThreepids } from "./AddRemoveThreepids"; type LoadingState = "loading" | "loaded" | "error"; interface ThreepidSectionWrapperProps { error: string; loadingState: LoadingState; children: React.ReactNode; } const ThreepidSectionWrapper: React.FC = ({ error, loadingState, children }) => { if (loadingState === "loading") { return ; } else if (loadingState === "error") { return ( {error} ); } else { return <>{children}; } }; interface UserPersonalInfoSettingsProps { canMake3pidChanges: boolean; } /** * Settings controls allowing the user to set personal information like email addresses. */ export const UserPersonalInfoSettings: React.FC = ({ canMake3pidChanges }) => { const [emails, setEmails] = useState(); const [phoneNumbers, setPhoneNumbers] = useState(); const [loadingState, setLoadingState] = useState<"loading" | "loaded" | "error">("loading"); const client = useMatrixClientContext(); const updateThreepids = useCallback(async () => { try { const threepids = await client.getThreePids(); setEmails(threepids.threepids.filter((a) => a.medium === ThreepidMedium.Email)); setPhoneNumbers(threepids.threepids.filter((a) => a.medium === ThreepidMedium.Phone)); setLoadingState("loaded"); } catch (e) { setLoadingState("error"); } }, [client]); useEffect(() => { updateThreepids().then(); }, [updateThreepids]); const onEmailsChange = useCallback(() => { updateThreepids().then(); }, [updateThreepids]); const onMsisdnsChange = useCallback(() => { updateThreepids().then(); }, [updateThreepids]); if (!SettingsStore.getValue(UIFeature.ThirdPartyID)) return null; return (

{_t("settings|general|personal_info")}

); }; export default UserPersonalInfoSettings;