Fix vendor creation bug

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-05-26 09:25:32 -07:00
parent 061c4cef2b
commit 17da3934b1
2 changed files with 25 additions and 20 deletions

View File

@@ -408,6 +408,13 @@ function ListVendorContent({
"The vendor has been added successfully", "The vendor has been added successfully",
}); });
}, },
onError: (error) => {
toast({
title: "Error",
description: error.message || "Failed to create vendor",
variant: "destructive",
});
}
}); });
}} }}
> >

View File

@@ -270,11 +270,6 @@ func (s VendorService) Create(
req CreateVendorRequest, req CreateVendorRequest,
) (*coredata.Vendor, error) { ) (*coredata.Vendor, error) {
now := time.Now() now := time.Now()
var vendor *coredata.Vendor
err := s.svc.pg.WithTx(
ctx,
func(conn pg.Conn) error {
vendor := &coredata.Vendor{ vendor := &coredata.Vendor{
ID: gid.New(s.svc.scope.GetTenantID(), coredata.VendorEntityType), ID: gid.New(s.svc.scope.GetTenantID(), coredata.VendorEntityType),
Name: req.Name, Name: req.Name,
@@ -294,6 +289,9 @@ func (s VendorService) Create(
TermsOfServiceURL: req.TermsOfServiceURL, TermsOfServiceURL: req.TermsOfServiceURL,
} }
err := s.svc.pg.WithTx(
ctx,
func(conn pg.Conn) error {
organization := &coredata.Organization{} organization := &coredata.Organization{}
if err := organization.LoadByID(ctx, conn, s.svc.scope, req.OrganizationID); err != nil { if err := organization.LoadByID(ctx, conn, s.svc.scope, req.OrganizationID); err != nil {
return fmt.Errorf("cannot load organization %q: %w", req.OrganizationID, err) return fmt.Errorf("cannot load organization %q: %w", req.OrganizationID, err)