Fix non mandatory fields on vendor
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -10,6 +10,7 @@ type Props = {
|
|||||||
name: string;
|
name: string;
|
||||||
label?: string;
|
label?: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
|
optional?: boolean;
|
||||||
} & ComponentProps<typeof Field>;
|
} & ComponentProps<typeof Field>;
|
||||||
|
|
||||||
export function PeopleSelectField({
|
export function PeopleSelectField({
|
||||||
@@ -27,6 +28,7 @@ export function PeopleSelectField({
|
|||||||
control={control}
|
control={control}
|
||||||
name={props.name}
|
name={props.name}
|
||||||
disabled={props.disabled}
|
disabled={props.disabled}
|
||||||
|
optional={props.optional}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</Field>
|
</Field>
|
||||||
@@ -34,7 +36,7 @@ export function PeopleSelectField({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function PeopleSelectWithQuery(
|
function PeopleSelectWithQuery(
|
||||||
props: Pick<Props, "organizationId" | "control" | "name" | "disabled">
|
props: Pick<Props, "organizationId" | "control" | "name" | "disabled" | "optional">
|
||||||
) {
|
) {
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
const { name, organizationId, control } = props;
|
const { name, organizationId, control } = props;
|
||||||
@@ -51,12 +53,15 @@ function PeopleSelectWithQuery(
|
|||||||
id={name}
|
id={name}
|
||||||
variant="editor"
|
variant="editor"
|
||||||
placeholder={__("Select an owner")}
|
placeholder={__("Select an owner")}
|
||||||
onValueChange={field.onChange}
|
onValueChange={(value) => field.onChange(value === "__NONE__" ? null : value)}
|
||||||
key={people?.length.toString() ?? "0"}
|
key={people?.length.toString() ?? "0"}
|
||||||
{...field}
|
{...field}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
value={field.value ?? ""}
|
value={field.value ?? (props.optional ? "__NONE__" : "")}
|
||||||
>
|
>
|
||||||
|
{props.optional && (
|
||||||
|
<Option value="__NONE__">{__("None")}</Option>
|
||||||
|
)}
|
||||||
{people?.map((p) => (
|
{people?.map((p) => (
|
||||||
<Option key={p.id} value={p.id} className="flex gap-2">
|
<Option key={p.id} value={p.id} className="flex gap-2">
|
||||||
<Avatar name={p.fullName} />
|
<Avatar name={p.fullName} />
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ const schema = z.object({
|
|||||||
certifications: z.array(z.string()),
|
certifications: z.array(z.string()),
|
||||||
securityPageUrl: z.string(),
|
securityPageUrl: z.string(),
|
||||||
trustPageUrl: z.string(),
|
trustPageUrl: z.string(),
|
||||||
businessOwnerId: z.string(),
|
businessOwnerId: z.string().nullish(),
|
||||||
securityOwnerId: z.string(),
|
securityOwnerId: z.string().nullish(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const vendorFormFragment = graphql`
|
const vendorFormFragment = graphql`
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ export default function VendorOverviewTab() {
|
|||||||
label={__("Business owner")}
|
label={__("Business owner")}
|
||||||
error={errors.businessOwnerId?.message}
|
error={errors.businessOwnerId?.message}
|
||||||
disabled={isSubmitting || isSnapshotMode}
|
disabled={isSubmitting || isSnapshotMode}
|
||||||
|
optional={true}
|
||||||
/>
|
/>
|
||||||
<PeopleSelectField
|
<PeopleSelectField
|
||||||
organizationId={organizationId}
|
organizationId={organizationId}
|
||||||
@@ -162,6 +163,7 @@ export default function VendorOverviewTab() {
|
|||||||
label={__("Security owner")}
|
label={__("Security owner")}
|
||||||
error={errors.securityOwnerId?.message}
|
error={errors.securityOwnerId?.message}
|
||||||
disabled={isSubmitting || isSnapshotMode}
|
disabled={isSubmitting || isSnapshotMode}
|
||||||
|
optional={true}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ type (
|
|||||||
SecurityPageURL *string
|
SecurityPageURL *string
|
||||||
TrustPageURL *string
|
TrustPageURL *string
|
||||||
StatusPageURL *string
|
StatusPageURL *string
|
||||||
BusinessOwnerID *gid.GID
|
BusinessOwnerID **gid.GID
|
||||||
SecurityOwnerID *gid.GID
|
SecurityOwnerID **gid.GID
|
||||||
ShowOnTrustCenter *bool
|
ShowOnTrustCenter *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,19 +303,27 @@ func (s VendorService) Update(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if req.BusinessOwnerID != nil {
|
if req.BusinessOwnerID != nil {
|
||||||
businessOwner := &coredata.People{}
|
if *req.BusinessOwnerID != nil {
|
||||||
if err := businessOwner.LoadByID(ctx, conn, s.svc.scope, *req.BusinessOwnerID); err != nil {
|
businessOwner := &coredata.People{}
|
||||||
return fmt.Errorf("cannot load business owner: %w", err)
|
if err := businessOwner.LoadByID(ctx, conn, s.svc.scope, **req.BusinessOwnerID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load business owner: %w", err)
|
||||||
|
}
|
||||||
|
vendor.BusinessOwnerID = &businessOwner.ID
|
||||||
|
} else {
|
||||||
|
vendor.BusinessOwnerID = nil
|
||||||
}
|
}
|
||||||
vendor.BusinessOwnerID = &businessOwner.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.SecurityOwnerID != nil {
|
if req.SecurityOwnerID != nil {
|
||||||
securityOwner := &coredata.People{}
|
if *req.SecurityOwnerID != nil {
|
||||||
if err := securityOwner.LoadByID(ctx, conn, s.svc.scope, *req.SecurityOwnerID); err != nil {
|
securityOwner := &coredata.People{}
|
||||||
return fmt.Errorf("cannot load security owner: %w", err)
|
if err := securityOwner.LoadByID(ctx, conn, s.svc.scope, **req.SecurityOwnerID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load security owner: %w", err)
|
||||||
|
}
|
||||||
|
vendor.SecurityOwnerID = &securityOwner.ID
|
||||||
|
} else {
|
||||||
|
vendor.SecurityOwnerID = nil
|
||||||
}
|
}
|
||||||
vendor.SecurityOwnerID = &securityOwner.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vendor.UpdatedAt = time.Now()
|
vendor.UpdatedAt = time.Now()
|
||||||
|
|||||||
@@ -1443,8 +1443,8 @@ func (r *mutationResolver) UpdateVendor(ctx context.Context, input types.UpdateV
|
|||||||
WebsiteURL: input.WebsiteURL,
|
WebsiteURL: input.WebsiteURL,
|
||||||
Category: input.Category,
|
Category: input.Category,
|
||||||
Certifications: input.Certifications,
|
Certifications: input.Certifications,
|
||||||
BusinessOwnerID: input.BusinessOwnerID,
|
BusinessOwnerID: &input.BusinessOwnerID,
|
||||||
SecurityOwnerID: input.SecurityOwnerID,
|
SecurityOwnerID: &input.SecurityOwnerID,
|
||||||
ShowOnTrustCenter: input.ShowOnTrustCenter,
|
ShowOnTrustCenter: input.ShowOnTrustCenter,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user