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

Refactor/show contact #95

Merged
merged 11 commits into from
Feb 11, 2025
Merged

Refactor/show contact #95

merged 11 commits into from
Feb 11, 2025

Conversation

aloraalee
Copy link
Collaborator

@aloraalee aloraalee commented Feb 10, 2025

Type of Change

  • refactor 🧑‍💻

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.

…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.
…e companyContacts to include fetch. Fix formatting. Move interfact out of apiCalls and rename to not duplicate UserData.
Copy link
Collaborator

@Crosswolfv1 Crosswolfv1 left a 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

@SmilodonP
Copy link
Collaborator

The related ticket in your PR is incorrect and links to one of my issues.

@aloraalee
Copy link
Collaborator Author

The related ticket in your PR is incorrect and links to one of my issues.

Fixed!

Copy link
Collaborator

@TDManning TDManning left a 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) => ({
Copy link
Collaborator

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.

Copy link
Collaborator Author

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) {
Copy link
Collaborator

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 }

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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);
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

@TDManning TDManning left a 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

@TDManning TDManning merged commit de04d25 into main Feb 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants