Skip to content

Commit

Permalink
feat(create): add flash message on success create entry
Browse files Browse the repository at this point in the history
  • Loading branch information
axmad386 committed Jul 27, 2022
1 parent 0e53f6d commit 6b2af6a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions app/Http/Controllers/Operations/CreateOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const CreateOperation: Trait<typeof CrudController> = (s) =>
// insert items to db
await this.crud.create(this.crud.getStrippedSaveRequest());

this.crud
.getRequest()
.session()
.flash("message", `New ${this.crud.entity_name} created`);

this.crud.setSaveAction();

return this.crud.performSaveAction();
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/Operations/UpdateOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ const UpdateOperation: Trait<typeof CrudController> = (s) =>
// insert items to db
await this.crud.update(id, this.crud.getStrippedSaveRequest());

this.crud.getRequest().session().flash("message", `${this.crud.entity_name} updated`);
this.crud
.getRequest()
.session()
.flash("message", `${this.crud.entity_name} updated`);

this.crud.setSaveAction();

Expand Down
6 changes: 4 additions & 2 deletions app/Http/Request/UserRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class UserRequest extends CrudRequest {
};
}

private passwordRequiredOrNullable(){
return this.crud.getCurrentOperation() == "create"? "required": "nullable";
private passwordRequiredOrNullable() {
return this.crud.getCurrentOperation() == "create"
? "required"
: "nullable";
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/Library/CrudPanel/Traits/Validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Validation: Trait<typeof BaseCrudPanel & Class<ISettings>> = (s) =>
class extends s {
public setValidation(formRequestClass: typeof FormRequest) {
const formRequestInstance = this.request.setFormRequest(formRequestClass);
if(formRequestInstance instanceof CrudRequest){
if (formRequestInstance instanceof CrudRequest) {
formRequestInstance.setCrud(this as any);
}
this.setRequiredFields(formRequestInstance);
Expand Down
4 changes: 2 additions & 2 deletions app/Library/CrudRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type CrudPanel from "./CrudPanel/CrudPanel";
class CrudRequest extends FormRequest {
public crud!: CrudPanel;

public setCrud(crud: CrudPanel){
public setCrud(crud: CrudPanel) {
this.crud = crud;
}
}

export default CrudRequest;
export default CrudRequest;
3 changes: 1 addition & 2 deletions app/resources/view/crud/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export default ({
</Table>
</ScrollArea>
</Paper>
<Paper shadow="xs" p="xs" className="text-center" mt="sm"
>
<Paper shadow="xs" p="xs" className="text-center" mt="sm">
<Button
compact
className="mr-3"
Expand Down

0 comments on commit 6b2af6a

Please sign in to comment.