As a logged in user I can edit my own snapshots so that I can update and amend the details of my original post
Acceptance Criteria
On the snapshot detail page of a post owned by the logged in user, an edit icon should be visible
Clicking on the edit icon should direct the user to an update form page
Form fields should be pre-populated with existing values for the snapshot
Following successful update submission, the user should be redirected back to the detail page for the specified snapshot
Tasks
[x] Include the EditDelete component as part of the Snapshot component, and use conditional statement to only display if the user owns the snapshot and the snapshotPage prop has ben passed. This ensures a user can only choose to edit their snapshot from the detail page.
[x] Create SnapshotEditForm page
[x] Make use of the useEffect hook to fetch and setSnapshot based on a specific snapshot id. This id should be retrieved and stored with the useParams() hook, which will read the id specified in the URL. Add id to the useEffect dependency array to ensure this hook runs every time the id changes. Also pass history to the useEffect dependency array so the hook will run if the url changes.
[x] De-structure data returned from get request and if the user is the owner of the snapshot, use these values to setSnapshotData. If the user is not the owner of the snapshot, direct them back to the home page.
[x] De-structure snapshotData and use these values to populate form fields in the return statement.
[x] Write handleSubmit function that appends the updated form values to formData and makes a put request to the snapshots API endpoint, specifying a specific snapshot id.
[x] Use history to push the user back to the snapshot detail page once the form data has been submitted successfully.
EPIC: #15
As a logged in user I can edit my own snapshots so that I can update and amend the details of my original post
Acceptance Criteria
Tasks