-
Notifications
You must be signed in to change notification settings - Fork 22
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
Upload api update #1449
Upload api update #1449
Changes from all commits
a32e539
9c91a66
b83d8e5
4d26203
644fd02
951db0f
b8c6264
c583c48
21d59c6
9844f55
8a0f745
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ const ConfigUploaderComponent = ({ onSelect, ...props }) => { | |
const [file, setFile] = useState(null); | ||
const [fileStoreId, setFileStoreId] = useState(null); | ||
const tenantId = Digit.ULBService.getCurrentTenantId(); | ||
const [uploadErrorMessage, setUploadErrorMessage] = useState(""); | ||
const { t } = useTranslation(); | ||
|
||
|
||
|
@@ -20,9 +21,11 @@ const ConfigUploaderComponent = ({ onSelect, ...props }) => { | |
const response = await Digit.UploadServices.Filestorage("Sandbox", file, tenantId); | ||
const fileStoreId = response?.data?.files?.[0]?.fileStoreId; | ||
setFileStoreId(fileStoreId) | ||
setUploadErrorMessage(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Rename The implementation of error handling using Consider renaming this prop to something like Example: <Uploader
// ...other props
errorMessage={uploadErrorMessage}
// ...
/> Make sure to update the Also applies to: 28-28, 62-62 |
||
} catch (error) { | ||
setToastMessage(t("BANNER_UPLOAD_FAILED")); | ||
setIsError(true); | ||
setUploadErrorMessage(t("BANNER_UPLOAD_FAILED")); | ||
setShowToast(true); | ||
setTimeout(() => { | ||
setShowToast(false); | ||
|
@@ -56,6 +59,7 @@ const ConfigUploaderComponent = ({ onSelect, ...props }) => { | |
uploadedFiles={[]} | ||
variant="uploadFile" | ||
onUpload={(files) => selectFile(files)} | ||
iserror={uploadErrorMessage} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Rename While the implementation is correct, the prop name Consider renaming this prop to something like <Uploader
// ...other props
errorMessage={uploadErrorMessage}
// ...
/> Make sure to update the |
||
accept="image/*, .jpg, .png, .jpeg" | ||
// if (files && files.length > 0) { | ||
// handleUploadFile(files); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,25 +5,29 @@ import { useTranslation } from "react-i18next"; | |
import { Fragment } from "react"; | ||
|
||
const LogoUploaderComponent = ({ onSelect, ...props }) => { | ||
const [file, setFile] = useState(null); | ||
const [fileStoreId, setFileStoreId] = useState(null); | ||
const [showToast, setShowToast] = useState(null); | ||
const [toastMessage, setToastMessage] = useState(""); | ||
const [isError, setIsError] = useState(false); | ||
const [file, setFile] = useState(null); | ||
const [fileStoreId, setFileStoreId] = useState(null); | ||
const tenantId = Digit.ULBService.getCurrentTenantId(); | ||
const [uploadErrorMessage, setUploadErrorMessage] = useState(""); | ||
const { t } = useTranslation(); | ||
|
||
const handleUploadFile = async () => { | ||
// Upload the file first | ||
try { | ||
const response = await Digit.UploadServices.Filestorage("Sandbox", file, tenantId); | ||
const fileStoreId = response?.data?.files?.[0]?.fileStoreId; | ||
setFileStoreId(fileStoreId) | ||
setUploadErrorMessage(""); | ||
} catch (error) { | ||
setToastMessage(t("LOGO_UPLOAD_FAILED")); | ||
setIsError(true); | ||
setUploadErrorMessage(t("LOGO_UPLOAD_FAILED")); | ||
setShowToast(true); | ||
setTimeout(() => { | ||
closeToast(); | ||
setShowToast(false); | ||
Comment on lines
+23
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Approve error handling improvements with a suggestion. The changes in the
These improvements align well with the PR objectives. To further enhance user experience, consider adding a success message for successful uploads: if (fileStoreId) {
setToastMessage(t("LOGO_UPLOAD_SUCCESS"));
setIsError(false);
setShowToast(true);
} This addition would provide positive feedback to users upon successful upload. |
||
}, 2000); | ||
} | ||
}; | ||
|
@@ -52,6 +56,7 @@ const LogoUploaderComponent = ({ onSelect, ...props }) => { | |
uploadedFiles={[]} | ||
variant="uploadFile" | ||
onUpload={(files) => selectFile(files)} | ||
iserror={uploadErrorMessage} | ||
accept="image/*, .jpg, .png, .jpeg" | ||
// if (files && files.length > 0) { | ||
// handleUploadFile(files); | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ const TenantConfigUpload = () => { | |||||||||||||
const [isError, setIsError] = useState(false); | ||||||||||||||
const [uploadData, setUploadData] = useState([]); // State to store the uploaded data | ||||||||||||||
const [tenantDocument, setDocuments] = useState([]); | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
||||||||||||||
const mutation = Digit.Hooks.useCustomAPIMutationHook({ | ||||||||||||||
|
@@ -74,6 +75,20 @@ const TenantConfigUpload = () => { | |||||||||||||
type: data[key]?.type, | ||||||||||||||
}; | ||||||||||||||
}); | ||||||||||||||
|
||||||||||||||
const isBannerUndefined = documents.find(doc => doc.type === "bannerUrl")?.fileStoreId === undefined; | ||||||||||||||
const isLogoUndefined = documents.find(doc => doc.type === "logoUrl")?.fileStoreId === undefined; | ||||||||||||||
|
||||||||||||||
if (isBannerUndefined && isLogoUndefined) { | ||||||||||||||
setToastMessage(t("BOTH_FILESTOREIDS_ARE_UNDEFINED")); | ||||||||||||||
setIsError(true); | ||||||||||||||
setShowToast(true); | ||||||||||||||
setTimeout(() => { | ||||||||||||||
setShowToast(false); | ||||||||||||||
}, 2000); | ||||||||||||||
return; | ||||||||||||||
Comment on lines
+86
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor toast dismissal logic for consistency. Multiple instances use Apply this diff to use the existing - setTimeout(() => {
- setShowToast(false);
- }, 2000);
+ closeToast(); If different durations are needed, modify 📝 Committable suggestion
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
Comment on lines
+78
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Approve validation logic with suggestion for improvement. The added validation logic improves user experience by preventing submission when both files are missing. However, consider if allowing submission when only one file is present is the desired behavior. If both files should be required, consider modifying the condition: if (isBannerUndefined || isLogoUndefined) {
setToastMessage(t("BOTH_FILES_REQUIRED"));
setIsError(true);
setShowToast(true);
return;
} |
||||||||||||||
setUploadData(documents); | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
|
@@ -127,12 +142,12 @@ const TenantConfigUpload = () => { | |||||||||||||
}, | ||||||||||||||
{ | ||||||||||||||
onError: (error) => { | ||||||||||||||
setToastMessage(error.message || t("ERROR_MESSAGE")); | ||||||||||||||
setToastMessage(error.message || t("CONFIG_UPLOAD_ERROR_MESSAGE")); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Improve error message handling, but consider further enhancement. The use of a fallback to a translated error message is an improvement. However, consider avoiding the display of raw error messages to users as they may contain sensitive information. Apply this diff for a more user-friendly approach: - setToastMessage(error.message || t("CONFIG_UPLOAD_ERROR_MESSAGE"));
+ setToastMessage(t("CONFIG_UPLOAD_ERROR_MESSAGE"));
+ console.error("API Error:", error.message); // Log the error for debugging This ensures a consistent user-friendly message while still logging the detailed error for debugging purposes. 📝 Committable suggestion
Suggested change
|
||||||||||||||
setIsError(true); | ||||||||||||||
setShowToast(true); | ||||||||||||||
Comment on lines
+145
to
147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid displaying raw error messages to users. Using Apply this diff to display a user-friendly error message: - setToastMessage(error.message || t("CONFIG_UPLOAD_ERROR_MESSAGE"));
+ setToastMessage(t("CONFIG_UPLOAD_ERROR_MESSAGE")); Consider logging the error details for debugging purposes. 📝 Committable suggestion
Suggested change
|
||||||||||||||
}, | ||||||||||||||
onSuccess: () => { | ||||||||||||||
setToastMessage(t("SANDBOX_TENANT_CREATE_SUCCESS_TOAST")); | ||||||||||||||
setToastMessage(t("CONFIG_UPLOAD_SUCCESSFUL_TOAST_MESSAGE")); | ||||||||||||||
setIsError(false); | ||||||||||||||
setShowToast(true); | ||||||||||||||
setTimeout(() => { | ||||||||||||||
|
@@ -146,6 +161,9 @@ const TenantConfigUpload = () => { | |||||||||||||
setToastMessage(error.message); | ||||||||||||||
setIsError(true); | ||||||||||||||
setShowToast(true); | ||||||||||||||
setTimeout(() => { | ||||||||||||||
setShowToast(false); | ||||||||||||||
}, 2000); | ||||||||||||||
Comment on lines
+164
to
+166
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor toast dismissal logic for consistency. As mentioned earlier, using Apply this diff: - setTimeout(() => {
- setShowToast(false);
- }, 2000);
+ closeToast(); Remember to modify the 📝 Committable suggestion
Suggested change
|
||||||||||||||
} | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
|
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.
🧹 Nitpick (assertive)
LGTM: Improved error handling implementation.
The overall implementation of error handling for file uploads is well done:
uploadErrorMessage
state (line 14).handleUploadFile
(lines 24 and 28).Uploader
component (line 62).These changes effectively address the PR objectives of implementing proper error messages and enhancing the user experience. The use of localized error messages is a good practice.
For further improvement, consider addressing the
iserror
prop naming issue mentioned in the previous comment.Also applies to: 24-24, 28-28, 62-62