Skip to content

Commit d06feb0

Browse files
committed
fix: save bio in profile object instead of in basic_info trait
1 parent d43c106 commit d06feb0

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

src/routes/BuildMyProfile/index.jsx

+16-17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { getTraits, scrollToTop, isProfileFormDataEmpty } from "utils/";
4646
import moment from "moment";
4747
import _ from "lodash";
4848
import { createTraits, updateTraits } from "services/traits";
49+
import { updateMemberData } from "services/memberData";
4950

5051
const formatDate = (date) => {
5152
let ret = new Date(
@@ -59,12 +60,13 @@ const BuildMyProfile = () => {
5960
const authUser = useSelector((state) => state.authUser);
6061
const [isLoading, setIsLoading] = useState(false);
6162
const [myProfileData, setMyProfileData] = useState({});
63+
const [bio, setBio] = useState("");
64+
6265
// form states
6366
const [formData, setFormData] = useState({
6467
title: "",
65-
bio: "",
6668
});
67-
const { title, bio } = formData;
69+
const { title } = formData;
6870
// get an empty job item
6971
const emptyJob = () => ({
7072
company: "",
@@ -190,6 +192,7 @@ const BuildMyProfile = () => {
190192
getAuthUserProfile()
191193
.then((result) => {
192194
setMyProfileData(result);
195+
setBio(result.description);
193196
})
194197
.catch((e) => {
195198
// eslint-disable-next-line no-console
@@ -218,11 +221,10 @@ const BuildMyProfile = () => {
218221
// fill title and bio to state
219222
if (basicInfoValue) {
220223
// Using shortBio as title has to do with v3 using this mapping
221-
const { description, shortBio: title } = basicInfoValue;
224+
const { shortBio: title } = basicInfoValue;
222225
setFormData((formData) => ({
223226
...formData,
224227
title: title || "",
225-
bio: description || "",
226228
}));
227229
}
228230
if (workExpValue) {
@@ -273,16 +275,15 @@ const BuildMyProfile = () => {
273275
scrollToTop();
274276
}, []);
275277

276-
// save title / bio
277-
const getTitleAndBioData = (basicInfo) => {
278-
const { title, bio } = formData;
278+
// save title
279+
const getTitle = (basicInfo) => {
280+
const { title } = formData;
279281
// mapped data
280282
let data = {
281283
shortBio: title,
282-
description: bio,
283284
};
284285
// check if basic info already exists. if so, update(put data). otherwise, post data.
285-
if (basicInfo == null && isProfileFormDataEmpty("bio", data)) {
286+
if (basicInfo == null && isProfileFormDataEmpty("title", data)) {
286287
return {
287288
action: "create",
288289
data: {
@@ -293,10 +294,8 @@ const BuildMyProfile = () => {
293294
},
294295
},
295296
};
296-
// return addMyTitleAndBio(authUser.handle, data);
297297
} else {
298298
if (isProfileFormDataEmpty("bio", data)) {
299-
// return updateMyTitleAndBio(authUser.handle, basicInfo, data);
300299
return {
301300
action: "update",
302301
data: {
@@ -451,8 +450,6 @@ const BuildMyProfile = () => {
451450
);
452451
};
453452

454-
// reach router, navigate programmatically
455-
const navigate = useNavigate();
456453
// on submit, save form and then navigate
457454
const handleSubmit = async (e) => {
458455
if (!canSubmit()) {
@@ -481,7 +478,7 @@ const BuildMyProfile = () => {
481478
const functions = [
482479
{
483480
val: basicInfoTraits,
484-
func: getTitleAndBioData,
481+
func: getTitle,
485482
},
486483
{
487484
val: workExperience,
@@ -533,6 +530,10 @@ const BuildMyProfile = () => {
533530
}
534531
}
535532

533+
if (myProfileData.description != bio && bio != null && bio.trim().length) {
534+
await updateMemberData(authUser.handle, { description: bio });
535+
}
536+
536537
setIsLoading(false);
537538
window.location.href = config.TOPCODER_COMMUNITY_WEBSITE_URL + "/home";
538539
};
@@ -598,9 +599,7 @@ const BuildMyProfile = () => {
598599
placeholder={"Enter your bio"}
599600
value={bio}
600601
name="bio"
601-
onChange={(e) =>
602-
handleInputChange(e.target.name, e.target.value)
603-
}
602+
onChange={(e) => setBio(e.target.value)}
604603
/>
605604
</FormField>
606605
</div>

src/utils/index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ export function scrollToTop() {
2323
*/
2424
export function isProfileFormDataEmpty(type, data) {
2525
switch (type) {
26-
case "bio":
27-
let { shortBio, description } = data;
28-
return (
29-
(shortBio && shortBio.length) || (description && description.length)
30-
);
26+
case "title":
27+
let { shortBio } = data;
28+
return shortBio && shortBio.length;
3129
case "work":
3230
let { cityTown, company, position, timePeriodFrom, timePeriodTo } = data;
3331
let response =

0 commit comments

Comments
 (0)