Skip to content

Commit

Permalink
Fix validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
elektronaut committed May 8, 2024
1 parent 42bbe1d commit b5af7cd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/assets/builds/pages_core/admin-dist.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/assets/builds/pages_core/admin-dist.js.map

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions app/controllers/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,26 @@ def edit; end
def create
@page = build_page(content_locale, page_params,
param_categories).tap(&:save)
if @page.valid?
respond_with_page(@page) do

respond_with_page(@page) do
if @page.valid?
redirect_to(edit_admin_page_url(content_locale, @page))
else
render action: :new
end
else
render action: :new
end
end

def update
if @page.update(page_params)
@page.categories = param_categories
respond_with_page(@page) do
@page.update(page_params)
respond_with_page(@page) do
if @page.valid?
@page.categories = param_categories
flash[:notice] = t("pages_core.changes_saved")
redirect_to edit_admin_page_url(content_locale, @page)
else
render action: :edit
end
else
render action: :edit
end
end

Expand Down
7 changes: 6 additions & 1 deletion app/javascript/components/PageForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ export default function PageForm(props: Props) {
method(url, data)
.then((response: Page.SerializedResource) => {
dispatch({ type: "setPage", payload: response });
noticeToast("Your changes were saved");
if (response.errors) {
console.log(response.errors);
errorToast("A validation error prevented the page from being saved.");
} else {
noticeToast("Your changes were saved");
}
})
.catch(() => {
errorToast("An error occured while saving your changes.");
Expand Down

0 comments on commit b5af7cd

Please sign in to comment.