-
Notifications
You must be signed in to change notification settings - Fork 0
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
Edit basic info modal/kirustar14/personal info modal #43
Edit basic info modal/kirustar14/personal info modal #43
Conversation
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 went ahead and moved the code from frontend/src/app/Components to frontend/src/components as discussed in Issue #19 Edit Basic Info Modal
To manually test this code, I used the attached frontend/src/app/page.tsx:
"use client";
import Image from "next/image";
import { useState } from "react";
import EditBasicInfoModal from "@/components/EditBasicInfoModal/EditBasicInfoModal";
export default function Home() {
const [isOpen, setIsOpen] = useState(false);
const handleOnSubmit = (data: {
firstName: string;
lastName: string;
email: string;
phone: string;
}) => {
console.log("Submitted Data:", data); // Log to verify form submission
};
return (
<button onClick={() => setIsOpen(true)}>Open Modal
<EditBasicInfoModal
isOpen={isOpen}
onClose={() => setIsOpen(false)}
onSubmit={handleOnSubmit}
/>
);
}
This code generally seems to meet most requirements for Issue #19 on Edit Basic Info Modal except that the component is not sufficiently vertically responsive as demonstrated by the screenshot below.
A fix would be to try to scale the component vertical window size as per the browser vertical window size. This concludes my PR review; I am not requesting changes as this might not be an essential fix.
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.
SINCE ROHAN MADE A COMMIT MAKE SURE TO PULL BEFORE PUSHING, IDEALLY PULL BEFORE MAKING PR REVIEW EDITS
Generally a good First Tasks.
CSS needs clean up and simplification and removal of repetition (Let me know if you need help)
Forgot to add in the task before hand (my bad) can you use the following resources below to handle the form input validation (also error messages) and react hook form optimizes things in terms of renderings
Tutorials/Resources
(Handles form field updates) https://react-hook-form.com/
(Input Validation) https://zod.dev/
Tutorial (on reacthook and zod working together)- https://www.freecodecamp.org/news/react-form-validation-zod-react-hook-form/
Also add in an index.ts file un the components folder to export the component (this will clean up the imports in the future)
See Onboarding example: https://github.com/TritonSE/onboarding/blob/main/frontend/src/components/index.ts
background: white; | ||
padding: 40px; | ||
border-radius: 15px; | ||
width: 657px; |
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 a big size to hard code in px. See if you can use rem, em, vw, vh
relative units. This will also make the pop up scale to screen size more easily likely addressing the problem Rohan brought up in his review
.close-button { | ||
position: absolute; | ||
top: 31px; | ||
left: 595px; |
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.
Same thing try relative units
|
||
/* Save Button Container */ | ||
.modal-footer button { | ||
width: 520.76px; |
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.
try relative units
If you are pulling the units from figma 520 is fin don't need to go until 520.76
font-weight: 400; | ||
font-size: 20px; | ||
line-height: 26.04px; | ||
color: #000000; |
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 we not just use black?
.phone-group input::placeholder { | ||
font-family: "DM Sans", sans-serif; | ||
font-weight: 400; | ||
font-size: 17px; | ||
line-height: 22.13px; | ||
color: #b4b4b4; | ||
} |
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.
A lot of repetition in code
Just give the elements with the same stylines the same class name
If need to be slightly different then give it an id attribute (which is unique) to target that specific element
<svg width="14" height="14" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg"> | ||
<line x1="0" y1="0" x2="14" y2="14" stroke="#000000" strokeWidth="1.5" /> | ||
<line x1="14" y1="0" x2="0" y2="14" stroke="#000000" strokeWidth="1.5" /> | ||
</svg> |
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.
Create a separate file for this svg under Public/icons
Then import it and use it -- > Max code more readable
Not sure where you code the code from but you can get it straight from the designers figma
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M5 19L12 12M12 12L19 5M12 12L5 5M12 12L19 19" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
See How they import and use the icon https://github.com/TritonSE/PAP-Inventory-Processing/blob/ea2e7275d40f10fca354eb749f253a52cc75ef60/frontend/src/components/VSRIndividual/VSRIndividualPage/index.tsx#L561-L566
const EditBasicInfoModal = ({ | ||
isOpen, | ||
onClose, | ||
onSubmit, |
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.
onSubmit doesn't need to be passed it
Since what will happen when submitting is sending the data collected in the form over to the backend
nothing exterior is necessary
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.
Overall The CSS for the model seems
Top and Left, Height, use for absolute shouldn't be needed so frequently
Usually adding padding and margin to the element and setting their gaps should be sufficient
const [phone, setPhone] = useState(""); | ||
|
||
// Modify handleSave to use onSubmit from parent | ||
const handleSave = () => { |
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.
Put this in a useCallback
useCallback is for optimizing rendering since unless its dependencies change when screen is rerendered it will not recreate the function
Docs: https://react.dev/reference/react/useCallback
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.
Looks Great! Just a few more css changes and it should be good.
phone: z | ||
.string() | ||
.min(1, "Phone Number is required") | ||
.refine((val) => val.length >= 10, { |
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.
It seems phonenumbers in the world can be from 5 to 15. We need to take into account phone numbers from different contries.
package-lock.json
Outdated
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 should be no package-lock.json at the root directory. Delete this file
const response = await fetch("/your-api-endpoint", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(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.
Create this as a function in src/api folder see the onboarding repo for reference. Let's keep all functions that call the backend defiend overthere. and then import and call it here
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.
CSS looks a lot cleaner!.
the modal still seems to big interms of the general size of an element.
For the determining relative sizes to use you can write the css start up the frontend inspect that element to see what the resulting size interms of pixels is and compare it to the figma and adjust.
I think the modal should be almost done but we just need to size down everything in the modal
ecc859f
to
daaf5d9
Compare
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.
Almost there just a few things about the fetch request and resolve the merge conflicts
frontend/src/app/page.tsx
Outdated
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.
let's keep this page.tsx as is
//not sure how to send data to backend | ||
const onSubmit: SubmitHandler<FormData> = async (data) => { | ||
try { | ||
const response = await fetchRequest("POST", "/your-api-endpoint", 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.
set the url endpoint to pull from env file.
https://github.com/TritonSE/PAP-Inventory-Processing/blob/ea2e7275d40f10fca354eb749f253a52cc75ef60/frontend/src/util/validateEnv.ts
frontend/src/app/page.tsx
Outdated
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.
let's keep this page as is
frontend/src/api/requests.ts
Outdated
@@ -0,0 +1,23 @@ | |||
type Method = "GET" | "POST" | "PUT"; | |||
|
|||
export async function fetchRequest( |
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.
rename this function to be specific to this modal and with more information
i.e. editBasicInfoRequest
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 backend route for this functionality should be in. (just a dummy one right now but you should be able to call it
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.
1-2 little notes and adjust the spacing for the save button as discussed in the meeting on wednessday.
It so close but you are almost there
resolver: zodResolver(schema), | ||
}); | ||
|
||
const onSubmit: SubmitHandler<FormData> = async (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.
put this in a usecallback
frontend/package-lock.json
Outdated
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.
package--lock looks like it took out some dependencies which should still be there. Just npm install again on the frontend folder
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.
Looks Good Great!
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 have reviewed this code and tested the Modal and it looked mostly good to me. Nice work on this, Kiruthika!
I realized the phone number validation was particularly weak, so I used a really standard regular expression for this purpose in conjunction with the zod validation in frontend/src/components/EditBasicInfoModal.tsx. I also added the normalization of phone numbers so that the formatting is standard when we store it (removing dots, dashes, spaces, parentheses). I think the minimum phone number length is 7 rather than 5 (ITU-T E.164) so I updated that.
It looks good to me, so I will pass it back to Helen to review and merge.
…nents as discussed in Issue #19 Edit Basic Info Modal
…alize phone number sent to backend
7aaca08
to
273388a
Compare
Tracking Info
Resolves #19
Changes
Fixed the edit basic info modal following Figma style.
Testing
Opened the modal in page.tsx and removed it after.
Confirmation of Change