Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lovincyrus committed Dec 6, 2024
1 parent 43e57a6 commit f5373ce
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
superForm(defaults(initialValues, schema), {
SPA: true,
validators: schema,
// See: https://superforms.rocks/concepts/nested-data
dataType: "json",
onResult: ({ result }) => {
if (result.type === "success") {
handleReset();
open = false;
}
},
Expand All @@ -91,15 +91,21 @@
// Check for duplicates before proceeding
const duplicates = checkForExistingKeys();
if (duplicates > 0) return;
if (duplicates > 0) {
// Early return without resetting the form
return;
}
// Only filter and process if there are no duplicates
const filteredVariables = values.variables.filter(
({ key }) => key !== "",
);
const flatVariables = Object.fromEntries(
filteredVariables.map(({ key, value }) => [key, value]),
);
try {
const filteredVariables = values.variables.filter(
({ key }) => key !== "",
);
const flatVariables = Object.fromEntries(
filteredVariables.map(({ key, value }) => [key, value]),
);
await handleUpdateProjectVariables(flatVariables);
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -156,7 +162,13 @@
}
function handleReset() {
// Reset form data to initial state
$form = {
variables: [{ key: "", value: "" }],
};
// Reset superForm state
reset();
// Reset other state
isDevelopment = true;
isProduction = true;
inputErrors = {};
Expand Down

0 comments on commit f5373ce

Please sign in to comment.