-
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
Refactor/show contact #95
Conversation
…Contact and ContactData interfaces in ShowContact.
… Contacts and NewContact to Interfaces. Delete prop with optional UserData since it wasn't being called anywhere.
…ns in apiCalls and move interfaces to Interfaces.tsx.
…ort in userInformation. Fix spacing.
…e companyContacts to include fetch. Fix formatting. Move interfact out of apiCalls and rename to not duplicate UserData.
…factor/ShowContact
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.
Amazing cleanup, I like the consolidation of the various objects and imports and the standardization of the case sensitivity across the code
The related ticket in your PR is incorrect and links to one of my issues. |
Fixed! |
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.
Good refactors overall. See notes for possible additional edits regarding "any" which I know that you had been working through.
src/apiCalls.tsx
Outdated
} | ||
|
||
const result = await response.json(); | ||
const companyList = result.data.map((company: any) => ({ |
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 looked into "any" for type here. Did you try ((company: Company)
? If you already tried this and it didn't work I have some ideas about why related to how Company and CompanyAttributes are defined in Interfaces.tsx.
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.
Nope, this is just one I missed, so thanks for catching that!
name: company.attributes.name, | ||
})); | ||
return companyList | ||
} catch (error: any) { |
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.
Possible Refactor:
In your catch blocks (error: any) could alternatively be (error: unknown)
for safer error handling. Your next line would need:
if (error instanceof Error)
{ error messages 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.
In doing some research, changing the code to error: unknown
does seem like best practice, so I implemented that suggestion for all instances where error was any. Any other refactoring of error handling for uniformity or robustness could be added as a task card for refactoring.
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.
After implementing those changes I am going to say that this is out of the scope of this task card because when trying to make changs to the error handling cypress tests were no longer passing, so it requires more than just a quick fix and this task card was just to move interfaces and apiCalls.
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 makes sense
src/apiCalls.tsx
Outdated
} | ||
} catch (error: any) { | ||
console.error("Error adding contact:", error); |
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.
Does this need error.message as well?
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 can make it more readable, yes. Implemented.
… Change error type to unknown and make error testing more robust.
…d to previous error messages.
…factor/ShowContact
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.
Thank you for the follow up on my comments. All comments resolved
Type of Change
Description
This PR moves the three interfaces from ShowContact to Interfaces.
It refactors and moves the fetchShowContact method to apiCalls.
It moves the two interfaces from Contact to Interfaces.
It moves the three interfaces from NewContact to Interfaces.
It moves the two interfaces from userInformation to Interfaces.
Motivation and Context
This PR follows the single responsibility principle and moves methods to their respective files.
Added Test?
No 🙅
All previous tests still pass 🥳
My code follows the code style of this project.
My change requires a change to the documentation.
I have updated the documentation accordingly.