84 lines
2.4 KiB
JavaScript
84 lines
2.4 KiB
JavaScript
import React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { connect } from "react-redux";
|
|
import { createStructuredSelector } from "reselect";
|
|
import { selectCurrentUser } from "../../redux/user/user.selectors";
|
|
import AlertComponent from "../alert/alert.component";
|
|
import { Form, Input, notification, Button } from "antd";
|
|
import { updateUserDetails } from "../../redux/user/user.actions";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
currentUser: selectCurrentUser
|
|
});
|
|
const mapDispatchToProps = dispatch => ({
|
|
updateUserDetails: userDetails => dispatch(updateUserDetails(userDetails))
|
|
});
|
|
export default connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps
|
|
)(
|
|
Form.create({ name: "ProfileMyComponentForm" })(function ProfileMyComponent({
|
|
currentUser,
|
|
form,
|
|
updateUserDetails
|
|
}) {
|
|
const { isFieldsTouched, resetFields, getFieldDecorator } = form;
|
|
const { t } = useTranslation();
|
|
|
|
const handleSubmit = e => {
|
|
e.preventDefault();
|
|
|
|
form.validateFieldsAndScroll((err, values) => {
|
|
if (err) {
|
|
notification["error"]({
|
|
message: t("jobs.errors.validationtitle"),
|
|
description: t("jobs.errors.validation")
|
|
});
|
|
}
|
|
if (!err) {
|
|
console.log("values", values);
|
|
updateUserDetails({
|
|
displayName: values.displayname,
|
|
photoURL: values.photoURL
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
{isFieldsTouched() ? (
|
|
//TODO: Appropriate Error
|
|
<AlertComponent
|
|
message={t("jobs.errors.validation")}
|
|
onClick={() => resetFields()}
|
|
/>
|
|
) : null}
|
|
|
|
<Form onSubmit={handleSubmit} autoComplete={"no"}>
|
|
<Form.Item label={t("user.fields.displayname")}>
|
|
{getFieldDecorator("displayname", {
|
|
initialValue: currentUser.displayName,
|
|
rules: [{ required: true }]
|
|
})(<Input name="displayname" />)}
|
|
</Form.Item>
|
|
<Form.Item label={t("user.fields.photourl")}>
|
|
{getFieldDecorator("photoURL", {
|
|
initialValue: currentUser.photoURL
|
|
})(<Input name="photoURL" />)}
|
|
</Form.Item>
|
|
|
|
<Button
|
|
type="primary"
|
|
key="submit"
|
|
htmlType="submit"
|
|
onClick={handleSubmit}
|
|
>
|
|
{t("user.actions.updateprofile")}
|
|
</Button>
|
|
</Form>
|
|
</div>
|
|
);
|
|
})
|
|
);
|