-
Notifications
You must be signed in to change notification settings - Fork 93
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
Feat: Issue#35 view user additional information #40
Conversation
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) |
a2c0571
to
15baa59
Compare
src/Enum.js
Outdated
@@ -0,0 +1,29 @@ | |||
export const TIMEZONE_ENUM = { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
which is what's being recorded in postgresql.
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).
The difference of the code are as per screenshoot below (the one commented out is returning timezone as its name, not value)
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/myspace/AdditionalInfo.jsx
Outdated
useEffect(() => { | ||
fetch(`${BASE_API}/user/additional_info`, requestAdditionalInfo) | ||
.then(async response => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it. now removed.
src/myspace/AdditionalInfo.jsx
Outdated
setAdditionalInfo(data); | ||
}) | ||
.catch(error => { | ||
setErrorMessage(data["message"]); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try
352e841
to
abd5e13
Compare
update @meenakshi-dhanani and @anitab-org/bridgeintech-maintainers . I've pushed the latest chage. Please re-review. |
src/myspace/AdditionalInfo.jsx
Outdated
fetch(`${BASE_API}/user/additional_info`, requestAdditionalInfo) | ||
.then(async response => { | ||
data = await response.json(); | ||
data.message ? setErrorMessage(data.message) : setAdditionalInfo(data); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
abd5e13
to
e97c918
Compare
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 |
ab8b294
to
b42e230
Compare
Update @meenakshi-dhanani and @anitab-org/bridgeintech-maintainers . I've made the requested changes. Can you please re-review? Ta |
src/myspace/AdditionalInfo.jsx
Outdated
import { BASE_API } from "../config"; | ||
import { AuthContext } from "../AuthContext"; | ||
import "./MySpace.css"; | ||
import { set } from "js-cookie"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unused
There was a problem hiding this comment.
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
src/myspace/AdditionalInfo.jsx
Outdated
}, | ||
}; | ||
|
||
const status = (response) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. 😉
7c2aca8
to
6404f62
Compare
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)
6404f62
to
6b990f1
Compare
src/myspace/AdditionalInfo.jsx
Outdated
if (response.ok) { | ||
setAdditionalInfo(data); | ||
} else { | ||
throw new Error(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can look at this today in our call - https://www.geeksforgeeks.org/reject-vs-throw-promises-in-javascript/
@ramitsawhney27 @foongminwong can you approve if it looks fine? I reviewed it with Maya |
There was a problem hiding this 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:
-
Code review - Done
-
All possible responses were tested as below:
PR 40
Screenshot/gif/url: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. -
OS Version: Windows 10
Description
Allow user to view their additional infomation page
Fixes #35
Type of Change:
Code/Quality Assurance Only
How Has This Been Tested?
By login with as a user and geet additional information page by following the path:
My Space
->Profile
-> onPersonal Details
page hitContinue
button and see below screenshots:if user is a representative of an organization:
![Screen Shot 2020-07-17 at 3 48 04 pm](https://user-images.githubusercontent.com/29667122/87753617-548cc900-c846-11ea-8cda-d230a885e36f.png)
if user is not a repreesentative of an organization:
![Screen Shot 2020-07-17 at 3 48 48 pm](https://user-images.githubusercontent.com/29667122/87753638-62424e80-c846-11ea-97dc-8dec1820b71c.png)
Checklist:
Code/Quality Assurance Only
Additional Note
This is a WIP. Still need to add tests and fix bugs