mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-24 18:59:17 +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 {
|
||||
initialTabId?: UserTab;
|
||||
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.
|
||||
* 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
|
||||
const [showMsc4108QrCode, setShowMsc4108QrCode] = useState(props.showMsc4108QrCode);
|
||||
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),
|
||||
// we show an indicator on the Encryption tab.
|
||||
@@ -131,7 +137,7 @@ export default function UserSettingsDialog(props: IProps): JSX.Element {
|
||||
UserTab.Account,
|
||||
_td("settings|account|title"),
|
||||
<UserProfileIcon />,
|
||||
<AccountUserSettingsTab closeSettingsFn={props.onFinished} />,
|
||||
<AccountUserSettingsTab closeSettingsFn={props.onFinished} startCustomStatus={startCustomStatus} />,
|
||||
"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
|
||||
setShowMsc4108QrCode(false);
|
||||
setInitialEncryptionState(undefined);
|
||||
setStartCustomStatus(false);
|
||||
};
|
||||
|
||||
const [activeToast, toastRack] = useActiveToast();
|
||||
|
||||
@@ -107,6 +107,8 @@ interface UserProfileSettingsProps {
|
||||
canSetDisplayName: boolean;
|
||||
// Whether the homeserver allows the user to set their avatar.
|
||||
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,
|
||||
canSetDisplayName,
|
||||
canSetAvatar,
|
||||
startCustomStatus,
|
||||
}) => {
|
||||
const [avatarURL, setAvatarURL] = useState(OwnProfileStore.instance.avatarMxc);
|
||||
const [displayName, setDisplayName] = useState(OwnProfileStore.instance.displayName ?? "");
|
||||
@@ -243,7 +246,7 @@ const UserProfileSettings: React.FC<UserProfileSettingsProps> = ({
|
||||
<ErrorMessage>{_t("settings|general|display_name_error")}</ErrorMessage>
|
||||
)}
|
||||
</EditInPlace>
|
||||
{userStatusEnabled && <SetStatusView vm={setStatusVM} />}
|
||||
{userStatusEnabled && <SetStatusView vm={setStatusVM} initialCustomMode={startCustomStatus} />}
|
||||
</Flex>
|
||||
</div>
|
||||
{avatarError && (
|
||||
|
||||
@@ -28,6 +28,10 @@ import { SDKContext } from "../../../../../contexts/SDKContext.ts";
|
||||
|
||||
interface IProps {
|
||||
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 {
|
||||
@@ -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 [canMake3pidChanges, setCanMake3pidChanges] = React.useState<boolean>(false);
|
||||
const [canSetDisplayName, setCanSetDisplayName] = React.useState<boolean>(false);
|
||||
@@ -182,6 +186,7 @@ const AccountUserSettingsTab: React.FC<IProps> = ({ closeSettingsFn }) => {
|
||||
externalAccountManagementUrl={externalAccountManagementUrl}
|
||||
canSetDisplayName={canSetDisplayName}
|
||||
canSetAvatar={canSetAvatar}
|
||||
startCustomStatus={startCustomStatus}
|
||||
/>
|
||||
{(!isAccountManagedExternally || canMake3pidChanges) && (
|
||||
<UserPersonalInfoSettings canMake3pidChanges={canMake3pidChanges} />
|
||||
|
||||
@@ -215,14 +215,15 @@ describe("UserMenuSetStatusViewModel", () => {
|
||||
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 });
|
||||
vm.onSetStatusClick();
|
||||
vm.onSetCustomStatusClick();
|
||||
await waitFor(() => {
|
||||
expect(dispatchSpy).toHaveBeenCalledWith({ action: Action.ToggleUserMenu });
|
||||
expect(dispatchSpy).toHaveBeenCalledWith({
|
||||
action: Action.ViewUserSettings,
|
||||
initialTabId: UserTab.Account,
|
||||
props: { startCustomStatus: true },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -85,13 +85,14 @@ export class UserMenuSetStatusViewModel extends SetStatusViewModel {
|
||||
super(props);
|
||||
}
|
||||
|
||||
public onSetStatusClick = (): void => {
|
||||
public onSetCustomStatusClick = (): void => {
|
||||
dis.dispatch({
|
||||
action: Action.ToggleUserMenu,
|
||||
});
|
||||
dis.dispatch({
|
||||
action: Action.ViewUserSettings,
|
||||
initialTabId: UserTab.Account,
|
||||
props: { startCustomStatus: true },
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import { mkStubRoom, stubClient } from "../../../../test-utils";
|
||||
import { OwnProfileStore } from "../../../../../src/stores/OwnProfileStore";
|
||||
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext";
|
||||
import Modal from "../../../../../src/Modal";
|
||||
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
||||
|
||||
interface MockedAvatarSettingProps {
|
||||
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(
|
||||
<TooltipProvider>
|
||||
<MatrixClientContext.Provider value={client}>
|
||||
<ToastContext.Provider value={toastRack as ToastRack}>
|
||||
<UserProfileSettings canSetAvatar={true} canSetDisplayName={true} />
|
||||
<UserProfileSettings
|
||||
canSetAvatar={true}
|
||||
canSetDisplayName={true}
|
||||
startCustomStatus={startCustomStatus}
|
||||
/>
|
||||
</ToastContext.Provider>
|
||||
</MatrixClientContext.Provider>
|
||||
</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 () => {
|
||||
jest.spyOn(OwnProfileStore.instance, "avatarMxc", "get").mockReturnValue("mxc://example.org/my-avatar");
|
||||
renderProfileSettings(toastRack, client);
|
||||
|
||||
@@ -56,6 +56,16 @@ describe("SetStatusView", () => {
|
||||
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 () => {
|
||||
const vm = new SetStatusViewModel({});
|
||||
render(<SetStatusView vm={vm} />);
|
||||
|
||||
@@ -42,11 +42,11 @@ export interface SetStatusViewSnapshot {
|
||||
|
||||
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.
|
||||
@@ -69,6 +69,13 @@ export type SetStatusViewModel = ViewModel<SetStatusViewSnapshot, SetStatusViewA
|
||||
|
||||
export type SetStatusViewProps = {
|
||||
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 {
|
||||
@@ -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 [customMode, setCustomMode] = useState(false);
|
||||
const [customMode, setCustomMode] = useState(initialCustomMode);
|
||||
|
||||
const renderItem = useCallback((value: StatusValue | null): React.ReactNode => {
|
||||
if (value === null) return null;
|
||||
@@ -129,7 +136,11 @@ export function SetStatusView({ vm }: SetStatusViewProps): JSX.Element {
|
||||
|
||||
const onValueChange = (value: StatusValue): void => {
|
||||
if (value === "custom") {
|
||||
setCustomMode(true);
|
||||
if (vm.onSetCustomStatusClick) {
|
||||
vm.onSetCustomStatusClick();
|
||||
} else {
|
||||
setCustomMode(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -145,9 +156,7 @@ export function SetStatusView({ vm }: SetStatusViewProps): JSX.Element {
|
||||
});
|
||||
};
|
||||
|
||||
return vm.onSetStatusClick ? (
|
||||
renderTrigger({ onClick: vm.onSetStatusClick })
|
||||
) : (
|
||||
return (
|
||||
<Dropdown<StatusValue>
|
||||
values={STATUS_KEYS}
|
||||
label={null}
|
||||
|
||||
Reference in New Issue
Block a user