mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-26 11:38:37 +00:00
Allow settings status directly from menu (#34707)
Clicking on custom now opens settings ready to enter a custom status so most of this PR is passing the flags through for the UI to start in that state.
This commit is contained in:
@@ -53,6 +53,11 @@ import { EncryptionUserSettingsTab, type State } from "../settings/tabs/user/Enc
|
|||||||
interface IProps {
|
interface IProps {
|
||||||
initialTabId?: UserTab;
|
initialTabId?: UserTab;
|
||||||
showMsc4108QrCode?: boolean;
|
showMsc4108QrCode?: boolean;
|
||||||
|
/*
|
||||||
|
* If true, the Account tab's status control starts in custom status mode,
|
||||||
|
* ready for the user to enter a custom status.
|
||||||
|
*/
|
||||||
|
startCustomStatus?: boolean;
|
||||||
/*
|
/*
|
||||||
* The initial state of the Encryption tab.
|
* The initial state of the Encryption tab.
|
||||||
* If undefined, the default state is used ("loading").
|
* If undefined, the default state is used ("loading").
|
||||||
@@ -102,6 +107,7 @@ export default function UserSettingsDialog(props: IProps): JSX.Element {
|
|||||||
// store these props in state as changing tabs back and forth should clear them
|
// store these props in state as changing tabs back and forth should clear them
|
||||||
const [showMsc4108QrCode, setShowMsc4108QrCode] = useState(props.showMsc4108QrCode);
|
const [showMsc4108QrCode, setShowMsc4108QrCode] = useState(props.showMsc4108QrCode);
|
||||||
const [initialEncryptionState, setInitialEncryptionState] = useState(props.initialEncryptionState);
|
const [initialEncryptionState, setInitialEncryptionState] = useState(props.initialEncryptionState);
|
||||||
|
const [startCustomStatus, setStartCustomStatus] = useState(props.startCustomStatus);
|
||||||
|
|
||||||
// If the user doesn't have Recovery set up (no default Secret Storage key),
|
// If the user doesn't have Recovery set up (no default Secret Storage key),
|
||||||
// we show an indicator on the Encryption tab.
|
// we show an indicator on the Encryption tab.
|
||||||
@@ -131,7 +137,7 @@ export default function UserSettingsDialog(props: IProps): JSX.Element {
|
|||||||
UserTab.Account,
|
UserTab.Account,
|
||||||
_td("settings|account|title"),
|
_td("settings|account|title"),
|
||||||
<UserProfileIcon />,
|
<UserProfileIcon />,
|
||||||
<AccountUserSettingsTab closeSettingsFn={props.onFinished} />,
|
<AccountUserSettingsTab closeSettingsFn={props.onFinished} startCustomStatus={startCustomStatus} />,
|
||||||
"UserSettingsGeneral",
|
"UserSettingsGeneral",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -258,6 +264,7 @@ export default function UserSettingsDialog(props: IProps): JSX.Element {
|
|||||||
// Clear these so switching away from the tab and back to it will not show the QR code again
|
// Clear these so switching away from the tab and back to it will not show the QR code again
|
||||||
setShowMsc4108QrCode(false);
|
setShowMsc4108QrCode(false);
|
||||||
setInitialEncryptionState(undefined);
|
setInitialEncryptionState(undefined);
|
||||||
|
setStartCustomStatus(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [activeToast, toastRack] = useActiveToast();
|
const [activeToast, toastRack] = useActiveToast();
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ interface UserProfileSettingsProps {
|
|||||||
canSetDisplayName: boolean;
|
canSetDisplayName: boolean;
|
||||||
// Whether the homeserver allows the user to set their avatar.
|
// Whether the homeserver allows the user to set their avatar.
|
||||||
canSetAvatar: boolean;
|
canSetAvatar: boolean;
|
||||||
|
// If true, the status control starts in custom status mode, ready for the user to enter a custom status.
|
||||||
|
startCustomStatus?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,6 +118,7 @@ const UserProfileSettings: React.FC<UserProfileSettingsProps> = ({
|
|||||||
externalAccountManagementUrl,
|
externalAccountManagementUrl,
|
||||||
canSetDisplayName,
|
canSetDisplayName,
|
||||||
canSetAvatar,
|
canSetAvatar,
|
||||||
|
startCustomStatus,
|
||||||
}) => {
|
}) => {
|
||||||
const [avatarURL, setAvatarURL] = useState(OwnProfileStore.instance.avatarMxc);
|
const [avatarURL, setAvatarURL] = useState(OwnProfileStore.instance.avatarMxc);
|
||||||
const [displayName, setDisplayName] = useState(OwnProfileStore.instance.displayName ?? "");
|
const [displayName, setDisplayName] = useState(OwnProfileStore.instance.displayName ?? "");
|
||||||
@@ -243,7 +246,7 @@ const UserProfileSettings: React.FC<UserProfileSettingsProps> = ({
|
|||||||
<ErrorMessage>{_t("settings|general|display_name_error")}</ErrorMessage>
|
<ErrorMessage>{_t("settings|general|display_name_error")}</ErrorMessage>
|
||||||
)}
|
)}
|
||||||
</EditInPlace>
|
</EditInPlace>
|
||||||
{userStatusEnabled && <SetStatusView vm={setStatusVM} />}
|
{userStatusEnabled && <SetStatusView vm={setStatusVM} initialCustomMode={startCustomStatus} />}
|
||||||
</Flex>
|
</Flex>
|
||||||
</div>
|
</div>
|
||||||
{avatarError && (
|
{avatarError && (
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ import { SDKContext } from "../../../../../contexts/SDKContext.ts";
|
|||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
closeSettingsFn: () => void;
|
closeSettingsFn: () => void;
|
||||||
|
/**
|
||||||
|
* If true, the status control starts in custom status mode, ready for the user to enter a custom status.
|
||||||
|
*/
|
||||||
|
startCustomStatus?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AccountSectionProps {
|
interface AccountSectionProps {
|
||||||
@@ -82,7 +86,7 @@ const ManagementSection: React.FC<ManagementSectionProps> = ({ onDeactivateClick
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const AccountUserSettingsTab: React.FC<IProps> = ({ closeSettingsFn }) => {
|
const AccountUserSettingsTab: React.FC<IProps> = ({ closeSettingsFn, startCustomStatus }) => {
|
||||||
const [externalAccountManagementUrl, setExternalAccountManagementUrl] = React.useState<string | undefined>();
|
const [externalAccountManagementUrl, setExternalAccountManagementUrl] = React.useState<string | undefined>();
|
||||||
const [canMake3pidChanges, setCanMake3pidChanges] = React.useState<boolean>(false);
|
const [canMake3pidChanges, setCanMake3pidChanges] = React.useState<boolean>(false);
|
||||||
const [canSetDisplayName, setCanSetDisplayName] = React.useState<boolean>(false);
|
const [canSetDisplayName, setCanSetDisplayName] = React.useState<boolean>(false);
|
||||||
@@ -182,6 +186,7 @@ const AccountUserSettingsTab: React.FC<IProps> = ({ closeSettingsFn }) => {
|
|||||||
externalAccountManagementUrl={externalAccountManagementUrl}
|
externalAccountManagementUrl={externalAccountManagementUrl}
|
||||||
canSetDisplayName={canSetDisplayName}
|
canSetDisplayName={canSetDisplayName}
|
||||||
canSetAvatar={canSetAvatar}
|
canSetAvatar={canSetAvatar}
|
||||||
|
startCustomStatus={startCustomStatus}
|
||||||
/>
|
/>
|
||||||
{(!isAccountManagedExternally || canMake3pidChanges) && (
|
{(!isAccountManagedExternally || canMake3pidChanges) && (
|
||||||
<UserPersonalInfoSettings canMake3pidChanges={canMake3pidChanges} />
|
<UserPersonalInfoSettings canMake3pidChanges={canMake3pidChanges} />
|
||||||
|
|||||||
@@ -215,14 +215,15 @@ describe("UserMenuSetStatusViewModel", () => {
|
|||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("dispatches ToggleUserMenu and ViewUserSettings on onSetStatusClick", async () => {
|
it("dispatches ToggleUserMenu and ViewUserSettings on onSetCustomStatusClick", async () => {
|
||||||
const vm = new UserMenuSetStatusViewModel({ client, ownProfileStore: mockOwnProfileStoreInstance });
|
const vm = new UserMenuSetStatusViewModel({ client, ownProfileStore: mockOwnProfileStoreInstance });
|
||||||
vm.onSetStatusClick();
|
vm.onSetCustomStatusClick();
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(dispatchSpy).toHaveBeenCalledWith({ action: Action.ToggleUserMenu });
|
expect(dispatchSpy).toHaveBeenCalledWith({ action: Action.ToggleUserMenu });
|
||||||
expect(dispatchSpy).toHaveBeenCalledWith({
|
expect(dispatchSpy).toHaveBeenCalledWith({
|
||||||
action: Action.ViewUserSettings,
|
action: Action.ViewUserSettings,
|
||||||
initialTabId: UserTab.Account,
|
initialTabId: UserTab.Account,
|
||||||
|
props: { startCustomStatus: true },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -85,13 +85,14 @@ export class UserMenuSetStatusViewModel extends SetStatusViewModel {
|
|||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
public onSetStatusClick = (): void => {
|
public onSetCustomStatusClick = (): void => {
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: Action.ToggleUserMenu,
|
action: Action.ToggleUserMenu,
|
||||||
});
|
});
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: Action.ViewUserSettings,
|
action: Action.ViewUserSettings,
|
||||||
initialTabId: UserTab.Account,
|
initialTabId: UserTab.Account,
|
||||||
|
props: { startCustomStatus: true },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { mkStubRoom, stubClient } from "../../../../test-utils";
|
|||||||
import { OwnProfileStore } from "../../../../../src/stores/OwnProfileStore";
|
import { OwnProfileStore } from "../../../../../src/stores/OwnProfileStore";
|
||||||
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext";
|
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext";
|
||||||
import Modal from "../../../../../src/Modal";
|
import Modal from "../../../../../src/Modal";
|
||||||
|
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
||||||
|
|
||||||
interface MockedAvatarSettingProps {
|
interface MockedAvatarSettingProps {
|
||||||
removeAvatar: () => void;
|
removeAvatar: () => void;
|
||||||
@@ -68,12 +69,20 @@ jest.mock("@vector-im/compound-web", () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderProfileSettings = (toastRack: Partial<ToastRack>, client: MatrixClient) => {
|
const renderProfileSettings = (
|
||||||
|
toastRack: Partial<ToastRack>,
|
||||||
|
client: MatrixClient,
|
||||||
|
{ startCustomStatus }: { startCustomStatus?: boolean } = {},
|
||||||
|
) => {
|
||||||
return render(
|
return render(
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
<MatrixClientContext.Provider value={client}>
|
<MatrixClientContext.Provider value={client}>
|
||||||
<ToastContext.Provider value={toastRack as ToastRack}>
|
<ToastContext.Provider value={toastRack as ToastRack}>
|
||||||
<UserProfileSettings canSetAvatar={true} canSetDisplayName={true} />
|
<UserProfileSettings
|
||||||
|
canSetAvatar={true}
|
||||||
|
canSetDisplayName={true}
|
||||||
|
startCustomStatus={startCustomStatus}
|
||||||
|
/>
|
||||||
</ToastContext.Provider>
|
</ToastContext.Provider>
|
||||||
</MatrixClientContext.Provider>
|
</MatrixClientContext.Provider>
|
||||||
</TooltipProvider>,
|
</TooltipProvider>,
|
||||||
@@ -91,6 +100,14 @@ describe("ProfileSettings", () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("shows the custom status editor when startCustomStatus is set", async () => {
|
||||||
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => name === "feature_user_status");
|
||||||
|
|
||||||
|
renderProfileSettings(toastRack, client, { startCustomStatus: true });
|
||||||
|
|
||||||
|
expect(await screen.findByRole("textbox", { name: "What's your status?" })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it("removes avatar", async () => {
|
it("removes avatar", async () => {
|
||||||
jest.spyOn(OwnProfileStore.instance, "avatarMxc", "get").mockReturnValue("mxc://example.org/my-avatar");
|
jest.spyOn(OwnProfileStore.instance, "avatarMxc", "get").mockReturnValue("mxc://example.org/my-avatar");
|
||||||
renderProfileSettings(toastRack, client);
|
renderProfileSettings(toastRack, client);
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ describe("SetStatusView", () => {
|
|||||||
expect(vm.setStatus).toHaveBeenCalledWith({ emoji: "🤩", text: "Starstruck" });
|
expect(vm.setStatus).toHaveBeenCalledWith({ emoji: "🤩", text: "Starstruck" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("starts in the custom editor if initialCustomMode is set", async () => {
|
||||||
|
const vm = new SetStatusViewModel({});
|
||||||
|
render(<SetStatusView vm={vm} initialCustomMode={true} />);
|
||||||
|
|
||||||
|
await userEvent.type(screen.getByRole("textbox", { name: "What's your status?" }), "Happy");
|
||||||
|
await userEvent.click(await screen.findByRole("button", { name: "Save" }));
|
||||||
|
|
||||||
|
expect(vm.setStatus).toHaveBeenCalledWith({ emoji: "😄", text: "Happy" });
|
||||||
|
});
|
||||||
|
|
||||||
it("returns to the set status prompt if the custom editor is cancelled", async () => {
|
it("returns to the set status prompt if the custom editor is cancelled", async () => {
|
||||||
const vm = new SetStatusViewModel({});
|
const vm = new SetStatusViewModel({});
|
||||||
render(<SetStatusView vm={vm} />);
|
render(<SetStatusView vm={vm} />);
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ export interface SetStatusViewSnapshot {
|
|||||||
|
|
||||||
export interface SetStatusViewActions {
|
export interface SetStatusViewActions {
|
||||||
/**
|
/**
|
||||||
* Called when the user clicks to start setting a status.
|
* Called when the user clicks to start setting a custom status.
|
||||||
*
|
*
|
||||||
* If falsy, the default dropdown will open for the user to choose a status.
|
* If falsy, the UI will change to allow the user to choose an emoji and enter text.
|
||||||
*/
|
*/
|
||||||
onSetStatusClick?: () => void;
|
onSetCustomStatusClick?: () => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user selects a preset status from the dropdown.
|
* Called when the user selects a preset status from the dropdown.
|
||||||
@@ -69,6 +69,13 @@ export type SetStatusViewModel = ViewModel<SetStatusViewSnapshot, SetStatusViewA
|
|||||||
|
|
||||||
export type SetStatusViewProps = {
|
export type SetStatusViewProps = {
|
||||||
vm: SetStatusViewModel;
|
vm: SetStatusViewModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, the view starts in custom status mode, ready for the user to enter a custom status.
|
||||||
|
*
|
||||||
|
* Ignored if the user already has a status set, as their existing status is shown instead.
|
||||||
|
*/
|
||||||
|
initialCustomMode?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
function StatusOption({ value }: { value: StatusValue }): React.ReactNode {
|
function StatusOption({ value }: { value: StatusValue }): React.ReactNode {
|
||||||
@@ -80,9 +87,9 @@ function StatusOption({ value }: { value: StatusValue }): React.ReactNode {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SetStatusView({ vm }: SetStatusViewProps): JSX.Element {
|
export function SetStatusView({ vm, initialCustomMode = false }: SetStatusViewProps): JSX.Element {
|
||||||
const { userStatus, recentEmojis } = useViewModel(vm);
|
const { userStatus, recentEmojis } = useViewModel(vm);
|
||||||
const [customMode, setCustomMode] = useState(false);
|
const [customMode, setCustomMode] = useState(initialCustomMode);
|
||||||
|
|
||||||
const renderItem = useCallback((value: StatusValue | null): React.ReactNode => {
|
const renderItem = useCallback((value: StatusValue | null): React.ReactNode => {
|
||||||
if (value === null) return null;
|
if (value === null) return null;
|
||||||
@@ -129,7 +136,11 @@ export function SetStatusView({ vm }: SetStatusViewProps): JSX.Element {
|
|||||||
|
|
||||||
const onValueChange = (value: StatusValue): void => {
|
const onValueChange = (value: StatusValue): void => {
|
||||||
if (value === "custom") {
|
if (value === "custom") {
|
||||||
setCustomMode(true);
|
if (vm.onSetCustomStatusClick) {
|
||||||
|
vm.onSetCustomStatusClick();
|
||||||
|
} else {
|
||||||
|
setCustomMode(true);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,9 +156,7 @@ export function SetStatusView({ vm }: SetStatusViewProps): JSX.Element {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return vm.onSetStatusClick ? (
|
return (
|
||||||
renderTrigger({ onClick: vm.onSetStatusClick })
|
|
||||||
) : (
|
|
||||||
<Dropdown<StatusValue>
|
<Dropdown<StatusValue>
|
||||||
values={STATUS_KEYS}
|
values={STATUS_KEYS}
|
||||||
label={null}
|
label={null}
|
||||||
|
|||||||
Reference in New Issue
Block a user