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

[IDOL, shoutouts] - edit shoutouts #578

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

[IDOL, shoutouts] - edit shoutouts #578

wants to merge 10 commits into from

Conversation

kevinmram
Copy link
Contributor

@kevinmram kevinmram commented Feb 12, 2024

added a button and functions for editing shoutouts , allowing users to edit their shoutouts after submission.

  • implemented the (Edit) button.
  • implemented the (editShoutout, updateShoutout) functions.
  • display the updated shoutout- without reversion after a refresh...
editing-shoutout.s.mp4

@dti-github-bot
Copy link
Member

dti-github-bot commented Feb 12, 2024

[diff-counting] Significant lines: 130.

Copy link
Contributor

@patriciaahuang patriciaahuang left a comment

Choose a reason for hiding this comment

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

Good job! I left a note about how to pass the last check. Also, it might be helpful to link the Notion ticket and an image for what you see on your end (edit button, success/error messages, etc), so reviewers can quickly check that we're see the same thing.

@kevinmram kevinmram changed the title editing-shoutout - init_imp. editing-shoutout(s) Sep 24, 2024
@kevinmram kevinmram marked this pull request as ready for review September 24, 2024 22:04
@kevinmram kevinmram requested a review from a team as a code owner September 24, 2024 22:04
@kevinmram kevinmram changed the title editing-shoutout(s) editing-shoutouts Sep 24, 2024
@andrew032011
Copy link
Collaborator

Screenshot 2024-09-24 at 6 26 30 PM Can you make it so that the spacing around the icon doesn't change as a result of adding this icon? The layout looks a little funky now since the icon is larger than the trash icon.

await this.collection.doc(uuid).update({ message: newMessage });
const updatedDoc = await this.getDocument(uuid);
if (!updatedDoc) {
throw new Error('Failed to fetch updated shoutout...');
Copy link
Collaborator

@andrew032011 andrew032011 Sep 24, 2024

Choose a reason for hiding this comment

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

Remove the ... in the string?

EDIT: also see Patricia's comment, we shouldn't be doing permissions checks here

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, could you use updateShoutout instead of creating a method just to edit the message?

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 more for future reference, but I think checking if the document exists in the DAO layer might be repetitive, since we already check if the uuid exists in the API layer. Not including the checks here also helps keep the DAO files consistent, since most of them do not have additional checks.

Copy link
Collaborator

@andrew032011 andrew032011 Sep 29, 2024

Choose a reason for hiding this comment

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

woah thanks for catching this @patriciaahuang, not sure how I didn't see it. We should not do any permissions checks at the DAO layer. That's reserved for the API layer! but since we're likely deleting this function anyways, yeah it's good to know for future reference.

if (!shoutout) {
throw new NotFoundError(`Shoutout with uuid: ${uuid} does not exist!`);
}
return shoutoutsDao.editShoutout(uuid, newMessage);
Copy link
Collaborator

Choose a reason for hiding this comment

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

see if you can use updateShoutout here instead

const [editedMessage, setEditedMessage] = useState(shoutout.message);

const handleEditShoutout = async () => {
try {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can do without this try/catch and console statement, since it doesn't do much other than console.log the error (which we would get in the console anyways). It would be worth it to try/catch if we had some sort of fallback code we wanted to run or wanted to record metrics.

newMessage: string,
user: IdolMember
): Promise<Shoutout> => {
const shoutout = await shoutoutsDao.getShoutout(uuid);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add permissions checking here to make sure that the shoutout belongs to the user who's trying to edit it OR it's a leadOrAdmin?

Copy link
Contributor

@patriciaahuang patriciaahuang left a comment

Choose a reason for hiding this comment

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

Overall functionality looks good! I agree with what Andrew said about using updateShoutouts instead of creating a new function. Also left a comment to help keep the DAO layer consistent.

await this.collection.doc(uuid).update({ message: newMessage });
const updatedDoc = await this.getDocument(uuid);
if (!updatedDoc) {
throw new Error('Failed to fetch updated shoutout...');
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 more for future reference, but I think checking if the document exists in the DAO layer might be repetitive, since we already check if the uuid exists in the API layer. Not including the checks here also helps keep the DAO files consistent, since most of them do not have additional checks.

@kevinmram kevinmram changed the title editing-shoutouts [IDOL, shoutouts] - edit shoutouts Sep 29, 2024
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.

5 participants