Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions django_email_learning/templates/platform/organizations.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"actions": "{% translate 'Actions' %}",
"name": "{% translate 'Name' %}",
"description": "{% translate 'Description' %}",
"name_required": "{% translate 'Name is required.' %}",
"description_required": "{% translate 'Description is required.' %}",
"error_try_again": "{% translate 'An error occurred. Please try again.' %}",
"logo": "{% translate 'Logo' %}",
"create_organization": "{% translate 'Create Organization' %}",
"cancel": "{% translate 'Cancel' %}",
Expand Down
31 changes: 29 additions & 2 deletions frontend/platform/organizations/components/OrganizationForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function OrganizationForm({ successCallback, failureCallback, cancelCallback, cr
const [logoFile, setLogoFile] = useState(null);
const [logoUrl, setLogoUrl] = useState(initialLogoUrl || null);
const [logoServerPath, setLogoServerPath] = useState(null);
const [errorMessages, setErrorMessages] = useState({});

const apiBaseUrl = localStorage.getItem('apiBaseUrl');

Expand All @@ -22,8 +23,30 @@ function OrganizationForm({ successCallback, failureCallback, cancelCallback, cr
setLogoFile(null);
}

const validateForm = () => {
let valid = true;
if (!name.trim()) {
setNameHelperText(localeMessages["name_required"]);
valid = false;
} else {
setNameHelperText("");
}

if (!description.trim()) {
setDescriptionHelperText(localeMessages["description_required"]);
valid = false;
} else {
setDescriptionHelperText("");
}

return valid;
}

const handleUpdate = () => (event) => {
event.preventDefault();
if (!validateForm()) {
return;
}

let payload = {
name: name,
Expand Down Expand Up @@ -58,12 +81,16 @@ function OrganizationForm({ successCallback, failureCallback, cancelCallback, cr
successCallback(data);
})
.catch(error => {
failureCallback(error);
setErrorMessages(localeMessages["error_try_again"]);
});
}

const handleCreate = () => (event) => {
event.preventDefault();
if (!validateForm()) {
return;
}

fetch(`${apiBaseUrl}/organizations/`, {
method: 'POST',
headers: {
Expand All @@ -88,7 +115,7 @@ function OrganizationForm({ successCallback, failureCallback, cancelCallback, cr
successCallback(data);
})
.catch(error => {
failureCallback(error);
setErrorMessages(localeMessages["error_try_again"]);
});
}

Expand Down