fix(s3-storage): add client-side validation before save, generic toast messages for empty fields

This commit is contained in:
KodekaTeam committed 2026-07-05 00:23:52 +07:00
1 parent a0bb8bd1cf
commit 8d13649fe0
1 file changed
+45 -8
+45 -8
View File
@@ -117,6 +117,23 @@ export default function S3StoragePage() {
}, []); }, []);
const upsertDestination = async (draft: DestinationDraft) => { const upsertDestination = async (draft: DestinationDraft) => {
const missing = [
!draft.accessKeyId && "Access Key ID",
!draft.secretAccessKey && "Secret Access Key",
!draft.region && "Region",
!draft.bucket && "Bucket",
!draft.name && "Destination Name",
].filter(Boolean) as string[];
if (missing.length > 0) {
pushToast({
tone: "warning",
// message: `Fill in the following fields before saving: ${missing.join(", ")}`,
message: `Fill in the available fields before proceeding with saving.`,
});
return false;
}
const pendingId = draft.id || "new-destination"; const pendingId = draft.id || "new-destination";
setSavingDestinationId(pendingId); setSavingDestinationId(pendingId);
try { try {
@@ -133,8 +150,8 @@ export default function S3StoragePage() {
message: message:
response.message || response.message ||
(draft.id (draft.id
? "Storage destination berhasil diperbarui" ? "Storage destination has been updated successfully"
: "Storage destination berhasil ditambahkan"), : "Storage destination has been created successfully"),
}); });
return true; return true;
} catch (err) { } catch (err) {
@@ -143,7 +160,7 @@ export default function S3StoragePage() {
message: message:
err instanceof Error err instanceof Error
? err.message ? err.message
: "Gagal menyimpan storage destination", : "Failed to save storage destination",
}); });
return false; return false;
} finally { } finally {
@@ -152,6 +169,23 @@ export default function S3StoragePage() {
}; };
const verifyDestination = async (draft: DestinationDraft) => { const verifyDestination = async (draft: DestinationDraft) => {
const missing = [
!draft.accessKeyId && "Access Key ID",
!draft.secretAccessKey && "Secret Access Key",
!draft.region && "Region",
!draft.bucket && "Bucket",
!draft.name && "Destination Name",
].filter(Boolean) as string[];
if (missing.length > 0) {
pushToast({
tone: "warning",
// message: `Fill in the following fields before verifying: ${missing.join(", ")}`,
message: `Fill in the available fields before proceeding with verification.`,
});
return;
}
setActionLoading(`verify-${draft.id ?? "draft"}`); setActionLoading(`verify-${draft.id ?? "draft"}`);
try { try {
@@ -169,7 +203,7 @@ export default function S3StoragePage() {
message: message:
err instanceof Error err instanceof Error
? err.message ? err.message
: "Gagal memverifikasi storage destination", : "Failed to verify destination connection",
}); });
} finally { } finally {
setActionLoading(null); setActionLoading(null);
@@ -194,7 +228,8 @@ export default function S3StoragePage() {
); );
pushToast({ pushToast({
tone: "success", tone: "success",
message: response.message || "Status storage destination diperbarui", message:
response.message || "Storage destination status updated successfully",
}); });
} catch (err) { } catch (err) {
pushToast({ pushToast({
@@ -202,7 +237,7 @@ export default function S3StoragePage() {
message: message:
err instanceof Error err instanceof Error
? err.message ? err.message
: "Gagal memperbarui status storage destination", : "Failed to update storage destination status",
}); });
} finally { } finally {
setSavingDestinationId(null); setSavingDestinationId(null);
@@ -222,7 +257,9 @@ export default function S3StoragePage() {
); );
pushToast({ pushToast({
tone: "success", tone: "success",
message: response.message || "Storage destination berhasil dihapus", message:
response.message ||
"Storage destination has been deleted successfully",
}); });
} catch (err) { } catch (err) {
pushToast({ pushToast({
@@ -230,7 +267,7 @@ export default function S3StoragePage() {
message: message:
err instanceof Error err instanceof Error
? err.message ? err.message
: "Gagal menghapus storage destination", : "Failed to delete storage destination",
}); });
} finally { } finally {
setSavingDestinationId(null); setSavingDestinationId(null);