diff --git a/app/frontend/src/javascript/components/form/form-image-upload.tsx b/app/frontend/src/javascript/components/form/form-image-upload.tsx index 2428992d7..4e449d2cd 100644 --- a/app/frontend/src/javascript/components/form/form-image-upload.tsx +++ b/app/frontend/src/javascript/components/form/form-image-upload.tsx @@ -31,7 +31,7 @@ export const FormImageUpload = (defaultImage); - const [image, setImage] = useState(defaultImage.attachment_url); + const [image, setImage] = useState(defaultImage?.attachment_url); useEffect(() => { setFile(defaultImage); @@ -118,7 +118,7 @@ export const FormImageUpload = = ({ action, machine, onErr * Callback triggered when the user validates the machine form: handle create or update */ const onSubmit: SubmitHandler = (data: Machine) => { - MachineAPI[action](data).then(() => { + MachineAPI[action](data).then((res) => { onSuccess(t(`app.admin.machine_form.${action}_success`)); + window.location.href = `/#!/machines/${res.slug}`; }).catch(error => { onError(error); }); diff --git a/app/frontend/src/javascript/controllers/machines.js.erb b/app/frontend/src/javascript/controllers/machines.js.erb index 2783f7c98..e74b8bbbf 100644 --- a/app/frontend/src/javascript/controllers/machines.js.erb +++ b/app/frontend/src/javascript/controllers/machines.js.erb @@ -231,7 +231,7 @@ Application.Controllers.controller('MachinesController', ['$scope', '$state', '_ /** * Controller used in the machine creation page (admin) */ -Application.Controllers.controller('NewMachineController', ['$scope', '$state', 'CSRF', function ($scope, $state, CSRF) { +Application.Controllers.controller('NewMachineController', ['$scope', '$state', 'CSRF', 'growl', function ($scope, $state, CSRF, growl) { CSRF.setMetaTags(); // API URL where the form will be posted @@ -244,6 +244,20 @@ Application.Controllers.controller('NewMachineController', ['$scope', '$state', $scope.machine = { machine_files_attributes: [] }; + /** + * Shows an error message forwarded from a child component + */ + $scope.onError = function (message) { + growl.error(message); + } + + /** + * Shows a success message forwarded from a child react components + */ + $scope.onSuccess = function (message) { + growl.success(message) + } + // Using the MachinesController return new MachinesController($scope, $state); } @@ -252,8 +266,8 @@ Application.Controllers.controller('NewMachineController', ['$scope', '$state', /** * Controller used in the machine edition page (admin) */ -Application.Controllers.controller('EditMachineController', ['$scope', '$state', '$transition$', 'machinePromise', 'CSRF', - function ($scope, $state, $transition$, machinePromise, CSRF) { +Application.Controllers.controller('EditMachineController', ['$scope', '$state', '$transition$', 'machinePromise', 'CSRF', 'growl', + function ($scope, $state, $transition$, machinePromise, CSRF, growl) { /* PUBLIC SCOPE */ // API URL where the form will be posted diff --git a/app/frontend/templates/machines/new.html b/app/frontend/templates/machines/new.html index 5f22617d8..048436a7c 100644 --- a/app/frontend/templates/machines/new.html +++ b/app/frontend/templates/machines/new.html @@ -26,6 +26,10 @@ {{ 'app.admin.machines_new.consider_changing_them_before_creating_any_reservation_slot' | translate }} - +
+
+ +
+
diff --git a/app/frontend/templates/machines/show.html b/app/frontend/templates/machines/show.html index 0f0879bc9..be0839103 100644 --- a/app/frontend/templates/machines/show.html +++ b/app/frontend/templates/machines/show.html @@ -39,8 +39,8 @@
-
- {{machine.name}} +
+ {{machine.name}}

@@ -69,7 +69,7 @@