2021-10-15 05:37:27 +00:00
|
|
|
import React, { useEffect } from "react";
|
2021-03-04 09:37:02 +00:00
|
|
|
import styled from "styled-components";
|
2022-10-13 20:13:44 +00:00
|
|
|
import { Toaster, Text, TextType } from "design-system";
|
2021-03-04 09:37:02 +00:00
|
|
|
import { debounce } from "lodash";
|
2022-08-22 05:09:39 +00:00
|
|
|
import { TextInput, notEmptyValidator } from "design-system";
|
2021-03-04 09:37:02 +00:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
|
import { Classes } from "@blueprintjs/core";
|
|
|
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
|
|
|
|
import { forgotPasswordSubmitHandler } from "pages/UserAuth/helpers";
|
|
|
|
|
import { Variant } from "components/ads/common";
|
2021-12-23 14:16:09 +00:00
|
|
|
import {
|
|
|
|
|
FORGOT_PASSWORD_SUCCESS_TEXT,
|
|
|
|
|
createMessage,
|
2022-02-11 18:08:46 +00:00
|
|
|
} from "@appsmith/constants/messages";
|
2021-03-04 09:37:02 +00:00
|
|
|
import { logoutUser, updateUserDetails } from "actions/userActions";
|
2022-08-24 12:16:32 +00:00
|
|
|
import { AppState } from "@appsmith/reducers";
|
2022-10-06 06:07:52 +00:00
|
|
|
import UserProfileImagePicker from "./UserProfileImagePicker";
|
2021-09-17 10:48:38 +00:00
|
|
|
import {
|
|
|
|
|
Wrapper,
|
|
|
|
|
FieldWrapper,
|
|
|
|
|
LabelWrapper,
|
|
|
|
|
Loader,
|
|
|
|
|
TextLoader,
|
|
|
|
|
} from "./StyledComponents";
|
2021-10-15 05:37:27 +00:00
|
|
|
import { getCurrentUser as refreshCurrentUser } from "actions/authActions";
|
2022-03-03 13:19:10 +00:00
|
|
|
import { getAppsmithConfigs } from "@appsmith/configs";
|
2022-05-20 09:07:02 +00:00
|
|
|
import { ANONYMOUS_USERNAME } from "constants/userConstants";
|
2022-03-03 13:19:10 +00:00
|
|
|
const { disableLoginForm } = getAppsmithConfigs();
|
2021-03-04 09:37:02 +00:00
|
|
|
|
|
|
|
|
const ForgotPassword = styled.a`
|
|
|
|
|
margin-top: 12px;
|
|
|
|
|
border-bottom: 1px solid transparent;
|
|
|
|
|
&:hover {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
}
|
|
|
|
|
display: inline-block;
|
|
|
|
|
`;
|
|
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
function General() {
|
2021-03-04 09:37:02 +00:00
|
|
|
const user = useSelector(getCurrentUser);
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const forgotPassword = async () => {
|
|
|
|
|
try {
|
|
|
|
|
await forgotPasswordSubmitHandler({ email: user?.email }, dispatch);
|
|
|
|
|
Toaster.show({
|
2022-03-28 06:03:22 +00:00
|
|
|
text: createMessage(FORGOT_PASSWORD_SUCCESS_TEXT, user?.email),
|
2021-03-04 09:37:02 +00:00
|
|
|
variant: Variant.success,
|
|
|
|
|
});
|
|
|
|
|
dispatch(logoutUser());
|
|
|
|
|
} catch (error) {
|
|
|
|
|
Toaster.show({
|
2022-06-21 13:57:34 +00:00
|
|
|
text: (error as { _error: string })._error,
|
2021-03-04 09:37:02 +00:00
|
|
|
variant: Variant.success,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const timeout = 1000;
|
|
|
|
|
const onNameChange = debounce((newName: string) => {
|
|
|
|
|
dispatch(
|
|
|
|
|
updateUserDetails({
|
|
|
|
|
name: newName,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}, timeout);
|
|
|
|
|
|
|
|
|
|
const isFetchingUser = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.users.loadingStates.fetchingUser,
|
|
|
|
|
);
|
|
|
|
|
|
2021-10-15 05:37:27 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
dispatch(refreshCurrentUser());
|
|
|
|
|
}, []);
|
|
|
|
|
|
2022-05-20 09:07:02 +00:00
|
|
|
if (user?.email === ANONYMOUS_USERNAME) return null;
|
|
|
|
|
|
2021-03-04 09:37:02 +00:00
|
|
|
return (
|
|
|
|
|
<Wrapper>
|
2021-06-16 18:36:34 +00:00
|
|
|
<FieldWrapper>
|
|
|
|
|
<LabelWrapper>
|
|
|
|
|
<Text type={TextType.H4}>Display Picture</Text>
|
|
|
|
|
</LabelWrapper>
|
|
|
|
|
<UserProfileImagePicker />
|
|
|
|
|
</FieldWrapper>
|
|
|
|
|
<FieldWrapper>
|
2021-03-04 09:37:02 +00:00
|
|
|
<LabelWrapper>
|
|
|
|
|
<Text type={TextType.H4}>Display name</Text>
|
|
|
|
|
</LabelWrapper>
|
2021-04-28 10:28:39 +00:00
|
|
|
{isFetchingUser && <Loader className={Classes.SKELETON} />}
|
2021-03-04 09:37:02 +00:00
|
|
|
{!isFetchingUser && (
|
2021-06-16 18:36:34 +00:00
|
|
|
<div style={{ flex: 1 }}>
|
|
|
|
|
<TextInput
|
|
|
|
|
cypressSelector="t--display-name"
|
|
|
|
|
defaultValue={user?.name}
|
|
|
|
|
fill={false}
|
|
|
|
|
onChange={onNameChange}
|
|
|
|
|
placeholder="Display name"
|
|
|
|
|
validator={notEmptyValidator}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2021-03-04 09:37:02 +00:00
|
|
|
)}
|
2021-06-16 18:36:34 +00:00
|
|
|
</FieldWrapper>
|
2021-03-04 09:37:02 +00:00
|
|
|
<FieldWrapper>
|
|
|
|
|
<LabelWrapper>
|
|
|
|
|
<Text type={TextType.H4}>Email</Text>
|
|
|
|
|
</LabelWrapper>
|
|
|
|
|
<div style={{ flexDirection: "column", display: "flex" }}>
|
|
|
|
|
{isFetchingUser && <TextLoader className={Classes.SKELETON} />}
|
|
|
|
|
{!isFetchingUser && <Text type={TextType.P1}>{user?.email}</Text>}
|
|
|
|
|
|
2022-03-03 13:19:10 +00:00
|
|
|
{!disableLoginForm && (
|
|
|
|
|
<ForgotPassword onClick={forgotPassword}>
|
|
|
|
|
Reset Password
|
|
|
|
|
</ForgotPassword>
|
|
|
|
|
)}
|
2021-03-04 09:37:02 +00:00
|
|
|
</div>
|
|
|
|
|
</FieldWrapper>
|
2021-06-16 18:36:34 +00:00
|
|
|
{/* <InputWrapper>
|
2021-03-04 09:37:02 +00:00
|
|
|
<LabelWrapper>
|
|
|
|
|
<Text type={TextType.H4}>Website</Text>
|
|
|
|
|
</LabelWrapper>
|
|
|
|
|
<TextInput
|
|
|
|
|
placeholder="Your website"
|
|
|
|
|
onChange={() => null}
|
|
|
|
|
defaultValue={""}
|
|
|
|
|
cypressSelector="t--profile-website"
|
|
|
|
|
/>
|
|
|
|
|
</InputWrapper> */}
|
|
|
|
|
</Wrapper>
|
|
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2021-03-04 09:37:02 +00:00
|
|
|
|
|
|
|
|
export default General;
|