Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Issue#35 view user additional information #40

Conversation

mtreacy002
Copy link
Member

Description

Allow user to view their additional infomation page

Fixes #35

Type of Change:

  • Code

Code/Quality Assurance Only

  • New feature (non-breaking change which adds functionality pre-approved by mentors)

How Has This Been Tested?

By login with as a user and geet additional information page by following the path:
My Space -> Profile -> on Personal Details page hit Continue button and see below screenshots:

  • if user is a representative of an organization:
    Screen Shot 2020-07-17 at 3 48 04 pm

  • if user is not a repreesentative of an organization:
    Screen Shot 2020-07-17 at 3 48 48 pm

Checklist:

  • My PR follows the style guidelines of this project
  • I have performed a self-review of my own code or materials

Code/Quality Assurance Only

  • My changes generate no new warnings
  • My PR currently breaks something (fix or feature that would cause existing functionality to not work as expected)
  • New and existing unit tests pass locally with my changes

Additional Note
This is a WIP. Still need to add tests and fix bugs

@mtreacy002 mtreacy002 self-assigned this Jul 17, 2020
@mtreacy002 mtreacy002 added Category: Coding Changes to code base or refactored code that doesn't fix a bug. Program: GSOC Related to work completed during the Google Summer of Code Program. labels Jul 17, 2020
@mtreacy002 mtreacy002 added this to the GSoC: Coding Phase II milestone Jul 17, 2020
@mtreacy002
Copy link
Member Author

Update @meenakshi-dhanani and @anitab-org/bridgeintech-maintainers . Here's the PR for View User's Additional Information page. This is still WIP as it doesn't have tests yet and still have minor bugs need to be fixed (to do with routing/navigating to previous page)

@mtreacy002 mtreacy002 changed the title WIP | Feat: Issue#35 view user additional information Feat: Issue#35 view user additional information Jul 17, 2020
@mtreacy002 mtreacy002 force-pushed the issue#35-view-user-additional-information branch 2 times, most recently from a2c0571 to 15baa59 Compare July 18, 2020 01:11
src/Enum.js Outdated
@@ -0,0 +1,29 @@
export const TIMEZONE_ENUM = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no enum in javascript. There are objects that have key value pairs. You can simply call it timezones

Copy link
Member Author

@mtreacy002 mtreacy002 Jul 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meenakshi-dhanani , the reason I did this is because the backend respond to this request with the timezone enum name
Screen Shot 2020-07-19 at 10 30 46 pm

which is what's being recorded in postgresql.
Screen Shot 2020-07-19 at 10 27 25 pm

Screen Shot 2020-07-19 at 10 32 15 pm

Screen Shot 2020-07-19 at 10 59 28 pm

However, what I want the user to see is the timezone value which according to this stackoverflow discussion could be done in in this way (what I've done in the code).

Screen Shot 2020-07-19 at 10 28 15 pm

The difference of the code are as per screenshoot below (the one commented out is returning timezone as its name, not value)
Screen Shot 2020-07-19 at 10 55 16 pm

There is another alternative, which is to change the backend response and request model to accept/return human-readable format (aka enum value) from the backend side and do the logic to convert it to enum name before saving it to the database.
But again, seeing how we keep machine format (unix datetime) for datetime on our backend and only change it to human-readable on frontend, I thought there's a convention somewhere (I'm not sure if there is, but @ramitsawhney27 maybe can clarify this for us) to keep backend as close as machine language

Screen Shot 2020-07-19 at 10 31 12 pm

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose to keep the mapping logic in the frontend/backend. And follow it consistently. Based on our discussion, keeping it in the backend right now is less effort. So you can continue with that. So frontend will not keep any mappings, as per my understanding

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. will change it now.

useEffect(() => {
fetch(`${BASE_API}/user/additional_info`, requestAdditionalInfo)
.then(async response => {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. now removed.

setAdditionalInfo(data);
})
.catch(error => {
setErrorMessage(data["message"]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this data.message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try

@mtreacy002 mtreacy002 added the Status: On Hold Issue or PR needs more info, a discussion, a review or approval from a Maintainer/Code Owner. label Jul 19, 2020
@mtreacy002 mtreacy002 changed the title Feat: Issue#35 view user additional information WIP | Feat: Issue#35 view user additional information Jul 19, 2020
@mtreacy002 mtreacy002 force-pushed the issue#35-view-user-additional-information branch 2 times, most recently from 352e841 to abd5e13 Compare July 20, 2020 03:09
@mtreacy002
Copy link
Member Author

update @meenakshi-dhanani and @anitab-org/bridgeintech-maintainers . I've pushed the latest chage. Please re-review.

@mtreacy002 mtreacy002 requested review from meenakshi-dhanani and a team July 20, 2020 03:12
@mtreacy002 mtreacy002 removed the Status: On Hold Issue or PR needs more info, a discussion, a review or approval from a Maintainer/Code Owner. label Jul 20, 2020
@mtreacy002 mtreacy002 changed the title WIP | Feat: Issue#35 view user additional information Feat: Issue#35 view user additional information Jul 20, 2020
fetch(`${BASE_API}/user/additional_info`, requestAdditionalInfo)
.then(async response => {
data = await response.json();
data.message ? setErrorMessage(data.message) : setAdditionalInfo(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error message is already getting set in catch right? would there be a case that on error the control would not go to a catch? Just wondering?

Copy link
Member Author

@mtreacy002 mtreacy002 Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meenakshi-dhanani . For some reason, it seems like only the uncustomised errors get inside catch. where as the customised errors did not get inside catch. you can test this by running the app, login, but skip going to personal details page and go straight to additional info. with error also set inside get, you'll see the error message. but if you comment it out and just relying from the one inside catch, you'll not see the error message. I don't know why this happen, but maybe just the way fetch is, or perhaps something in backend need to be change. Any suggestions? cc @ramitsawhney27

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mtreacy002 I checked fetch it works that way. Doesn't reject a 400. I'm looking at why and figuring another way. I'll post links on this soon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the documentation - https://javascript.info/fetch. Fetch doesn't reject http status errors. Usually how we handle it is since this same logic will be repeated for every call, we have a wrapper over api calls. You can push this and I can open another PR for that. However even in this, what you'd want to do it, check if the !response.ok and reject the promise with the data. Let catch then be the only place where you setErrorMessage. Once you reject anything, it will go to the catch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject - Inside the new error you can give the data from response.json

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. made the change. will push now

@mtreacy002 mtreacy002 force-pushed the issue#35-view-user-additional-information branch from abd5e13 to e97c918 Compare July 21, 2020 02:39
@mtreacy002
Copy link
Member Author

Update @anitab-org/bridgeintech-maintainers . I've added backend Heroku pr app server url to config. I may do the same on the next PR as well (not promising) so you can test frontend with the matching PR Heroku backend server instead of running locally

@mtreacy002 mtreacy002 force-pushed the issue#35-view-user-additional-information branch 2 times, most recently from ab8b294 to b42e230 Compare July 22, 2020 05:08
@mtreacy002
Copy link
Member Author

Update @meenakshi-dhanani and @anitab-org/bridgeintech-maintainers . I've made the requested changes. Can you please re-review? Ta

@mtreacy002 mtreacy002 requested review from meenakshi-dhanani and a team July 22, 2020 05:09
import { BASE_API } from "../config";
import { AuthContext } from "../AuthContext";
import "./MySpace.css";
import { set } from "js-cookie";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unused

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot this one too. Now it''s removed

},
};

const status = (response) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this const status is also not being used. You can remove this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops.. forgot to remove it. Ok. done now. 😉

@mtreacy002 mtreacy002 force-pushed the issue#35-view-user-additional-information branch 3 times, most recently from 7c2aca8 to 6404f62 Compare July 22, 2020 13:14
Remove buttons from the form and fix navigation

Replace cookies with token from authcontext

Refactor timezone logic and fix data setting

Add Heroku PR app url to config for backend server alternative

Throw error if response not 200

throw error if response not 200 for personal details

remove unused constant

remove unused import

Remove extra closing curly bracket

Refactored throw to Error(data)
@mtreacy002 mtreacy002 force-pushed the issue#35-view-user-additional-information branch from 6404f62 to 6b990f1 Compare July 23, 2020 01:44
if (response.ok) {
setAdditionalInfo(data);
} else {
throw new Error(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meenakshi-dhanani
Copy link
Contributor

@ramitsawhney27 @foongminwong can you approve if it looks fine? I reviewed it with Maya

Copy link

@foongminwong foongminwong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes made in this PR were tested locally. Following are the results:

  1. Code review - Done

  2. All possible responses were tested as below:

    PR 40
    Screenshot/gif/url:

    test-pr-40

    Expected Result: As a user, I should be able to view user additional information. If user additional information is not present, it should notify the user to click o the Personal Details page first.
    Actual Result: Same as expected.

  3. OS Version: Windows 10

@foongminwong foongminwong merged commit 59eac9b into anitab-org:develop Jul 25, 2020
@mtreacy002 mtreacy002 deleted the issue#35-view-user-additional-information branch September 12, 2020 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Coding Changes to code base or refactored code that doesn't fix a bug. Program: GSOC Related to work completed during the Google Summer of Code Program.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

View User Profile - Additional Information
3 participants