-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Conversation
[diff-counting] Significant lines: 130. |
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 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.
await this.collection.doc(uuid).update({ message: newMessage }); | ||
const updatedDoc = await this.getDocument(uuid); | ||
if (!updatedDoc) { | ||
throw new Error('Failed to fetch updated shoutout...'); |
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.
Remove the ...
in the string?
EDIT: also see Patricia's comment, we shouldn't be doing permissions checks 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.
Also, could you use updateShoutout
instead of creating a method just to edit the 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.
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.
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.
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); |
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.
see if you can use updateShoutout
here instead
const [editedMessage, setEditedMessage] = useState(shoutout.message); | ||
|
||
const handleEditShoutout = async () => { | ||
try { |
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 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); |
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 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?
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 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...'); |
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 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.
added a button and functions for editing shoutouts , allowing users to edit their shoutouts after submission.
editing-shoutout.s.mp4