Aditya-feat: Add Network Failure Handling & Upload Status Feedback on Update Tool/Equipment Status Page#4999
Open
Aditya-gam wants to merge 4 commits intodevelopmentfrom
Conversation
Add optional image param to updateEquipment; when present send multipart/form-data with field 'image' and do not set Content-Type. Restrict accepted formats to PNG/JPEG and 5MB in UpdateEquipment and DragAndDrop. Validate before submit and surface backend error message; clear file state on success and append note when image not saved on failure. Made-with: Cursor
Replace edit-button modal with Link to /bmdashboard/tools/:id/update so users open the full update page. Remove UpdateItemModal prop and related state from ToolItemsTable. Made-with: Cursor
✅ Deploy Preview for highestgoodnetwork-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Replace pencil button that opened UpdatesEdit modal with Link to /bmdashboard/tools/:id/update so users open the full Update Tool/Equipment Status page from the equipment list table. Made-with: Cursor
Revert pencil from Link to update page back to button that opens UpdateItemModal. Restore UpdateItemModal prop and related state (updateModal, updateRecord) and handleEditRecordsClick. Made-with: Cursor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Adds image upload and upload-status feedback on the BM Dashboard Update Tool/Equipment Status page (

/bmdashboard/tools/:equipmentId/update). The page previously only previewed images locally; this PR submits the selected image to the backend via the existing status-update API (multipart when an image is present), validates format (PNG/JPG/JPEG) and size (max 5 MB) before submit, and ensures every submission attempt results in clear success or failure feedback—including a user-friendly message when offline or when the image could not be saved (e.g. "No response from server. Please check your connection." and "Image selected but not saved."). The tools table is updated so the pencil icon links to the full update page instead of opening an update modal.Related PRs (if any):
multipart/form-data(fieldimage), validates PNG/JPEG/5 MB, stores in Azure, and persistsimageUrlon equipment and update record.Main changes explained:
Created/Updated Files:
src/actions/bmdashboard/equipmentActions.js(+26 / −3)updateEquipment(equipmentId, updateData, imageFile = null)— Added optional third argumentimageFile. WhenimageFileis provided, it builds aFormDatawith the same status fields (condition,createdBy,lastUsedBy,lastUsedFor,replacementRequired,description,notes) as form strings and appends the file under the field nameimage; it sendsPUTwith the FormData without settingContent-Typeso axios setsmultipart/form-datawith the correct boundary. WhenimageFileis null/undefined, it keeps the existing behavior: sends JSON body viaaxios.put(url, statusUpdateData).statusUpdateDataare normalized with|| ''for consistency when sent as form fields.err.response.data?.errorthenerr.response.data?.message; for no response (err.requestwithouterr.response) uses "No response from server. Please check your connection."; toasts error and rethrows.src/components/BMDashboard/Equipment/Update/UpdateEquipment.jsx(+66 / −33)ALLOWED_MIME_TYPES = ['image/png', 'image/jpeg'],MAX_IMAGE_SIZE_BYTES = 5 * 1024 * 1024,INVALID_IMAGE_MSG = 'Invalid image. Use PNG, JPG, or JPEG under 5MB.'(aligned with backend message).handleFileUpload: Restricts accepted files to PNG/JPEG (by MIME and extension\.(jpg|jpeg|png)$/i) and max 5 MB. When no valid files remain after filter, setssetSubmitError(INVALID_IMAGE_MSG)instead ofconsole.warn.handleSubmit: Before calling the action, when the user has selected files, validates the first file (type and size); if invalid, setssetSubmitError(INVALID_IMAGE_MSG)and returns without submitting. PassesuploadedFiles[0] ?? nullas the third argument toupdateEquipment. On success, shows "Equipment status updated successfully! Image saved." when an image was sent, otherwise "Equipment status updated successfully!"; always clears file preview state. On failure, builds error message fromerror.response?.data?.error(ormessage, or network message "No response from server. Please check your connection."); when images were selected, appends " Note: Images were selected and previewed but not saved to database." and marks previews asstatus: 'not-saved'. EnsuressetIsSubmitting(false)infinallyso no silent failures.src/components/common/DragAndDrop/DragAndDrop.jsx(+2 / −2)acceptattribute changed fromimage/jpeg, image/jpg, image/png, image/gif, image/webptoimage/png, image/jpeg, image/jpgto match backend.src/components/BMDashboard/ToolItemList/ToolItemsTable.jsx(+6 / −16)Linkto/bmdashboard/tools/${el._id}/updateso users go to the full Update Tool/Equipment Status page. RemovedUpdateItemModalprop and related state (updateModal,updateRecord) and handlerhandleEditRecordsClick. AddedLinkimport fromreact-router-dom. The "View" button for updating records remains and still opens the records modal.Key Implementation Details:
PUT /api/bm/equipment/:equipmentId/status(seeENDPOINTS.BM_EQUIPMENT_STATUS_UPDATE(equipmentId)insrc/utils/URL.js). With image: request ismultipart/form-datawith form fields plus one file under field nameimage; without image: request isapplication/jsonas before. Backend (PR fixed the edit time off request validation #2103) validates image type (PNG/JPEG) and size (5 MB) and returnsresponse.data.errorfor validation/upload failures.Content-Typeso the browser/axios can setmultipart/form-datawith the correct boundary, per backend contract.uploadedFiles[0]); backend accepts one file per request.err.response.data.error(thenmessage); network/offline case uses the fixed string "No response from server. Please check your connection." so offline submission always shows a clear toast and in-page error.ToolItemsTable(ToolItemListView) still passesUpdateItemModal; the prop is simply no longer used byToolItemsTable, so no parent change is required.How to test:
Aditya-feat/Add-Network–Failure-Handling-Upload-Status-Feedback-on-Update-Tool-Equipment-Status-Page.envfile.rm -rf node_modules && yarn cache cleanyarn installand start the app:yarn start:local/bmdashboard/tools/:equipmentId/updatewith a valid equipment ID fromGET /api/bm/equipments. I used these two for testing:6680a2ec7e038e1028825dde,6869da54b653924ff05eb471equipmentDetails.imageUrl)./bmdashboard/tools/:id/update(full update page) instead of opening a modal.response.data.error.Screenshots or videos of changes:
TestVideo.mov
Note:
Invalid image. Use PNG, JPG, or JPEG under 5MB.when invalid.imageUrlin response.