Fix audit and framework deletion
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -67,6 +67,8 @@ function AuditSelectWithQuery<T extends FieldValues = FieldValues>(
|
||||
const data = useLazyLoadQuery<AuditSelectFieldQuery>(auditsQuery, { organizationId }, { fetchPolicy: "network-only" });
|
||||
const audits = data?.organization?.audits?.edges?.map((edge) => edge.node).filter((node) => node !== null) ?? [];
|
||||
|
||||
const NONE_VALUE = "__NONE__";
|
||||
|
||||
return (
|
||||
<Controller
|
||||
control={control}
|
||||
@@ -77,12 +79,15 @@ function AuditSelectWithQuery<T extends FieldValues = FieldValues>(
|
||||
id={name}
|
||||
variant="editor"
|
||||
placeholder={__("Select an audit")}
|
||||
onValueChange={field.onChange}
|
||||
onValueChange={(value) => field.onChange(value === NONE_VALUE ? "" : value)}
|
||||
key={audits?.length.toString() ?? "0"}
|
||||
{...field}
|
||||
className="w-full"
|
||||
value={field.value ?? ""}
|
||||
value={field.value || NONE_VALUE}
|
||||
>
|
||||
<Option value={NONE_VALUE}>
|
||||
<span className="text-txt-tertiary">{__("None")}</span>
|
||||
</Option>
|
||||
{audits?.map((audit) => (
|
||||
<Option key={audit.id} value={audit.id}>
|
||||
<div className="flex items-center justify-between w-full">
|
||||
|
||||
@@ -112,7 +112,8 @@ export const deleteAuditMutation = graphql`
|
||||
|
||||
export const useDeleteAudit = (
|
||||
audit: { id: string; framework: { name: string } },
|
||||
connectionId: string
|
||||
connectionId: string,
|
||||
onSuccess?: () => void
|
||||
) => {
|
||||
const { __ } = useTranslate();
|
||||
const [mutate] = useMutationWithToasts(deleteAuditMutation, {
|
||||
@@ -123,15 +124,17 @@ export const useDeleteAudit = (
|
||||
|
||||
return () => {
|
||||
confirm(
|
||||
() =>
|
||||
mutate({
|
||||
async () => {
|
||||
await mutate({
|
||||
variables: {
|
||||
input: {
|
||||
auditId: audit.id!,
|
||||
},
|
||||
connections: [connectionId],
|
||||
},
|
||||
}),
|
||||
});
|
||||
onSuccess?.();
|
||||
},
|
||||
{
|
||||
message: sprintf(
|
||||
__(
|
||||
|
||||
@@ -168,7 +168,7 @@ export const useCreateNonconformity = (connectionId: string) => {
|
||||
organizationId: string;
|
||||
referenceId: string;
|
||||
description?: string;
|
||||
auditId: string;
|
||||
auditId?: string;
|
||||
dateIdentified?: string;
|
||||
rootCause: string;
|
||||
correctiveAction?: string;
|
||||
@@ -183,9 +183,6 @@ export const useCreateNonconformity = (connectionId: string) => {
|
||||
if (!input.referenceId) {
|
||||
return alert(__("Failed to create nonconformity: reference ID is required"));
|
||||
}
|
||||
if (!input.auditId) {
|
||||
return alert(__("Failed to create nonconformity: audit is required"));
|
||||
}
|
||||
if (!input.ownerId) {
|
||||
return alert(__("Failed to create nonconformity: owner is required"));
|
||||
}
|
||||
@@ -199,7 +196,7 @@ export const useCreateNonconformity = (connectionId: string) => {
|
||||
organizationId: input.organizationId,
|
||||
referenceId: input.referenceId,
|
||||
description: input.description,
|
||||
auditId: input.auditId,
|
||||
auditId: input.auditId || undefined,
|
||||
dateIdentified: input.dateIdentified,
|
||||
rootCause: input.rootCause,
|
||||
correctiveAction: input.correctiveAction,
|
||||
@@ -226,7 +223,7 @@ export const useUpdateNonconformity = () => {
|
||||
rootCause?: string;
|
||||
correctiveAction?: string;
|
||||
ownerId?: string;
|
||||
auditId?: string;
|
||||
auditId?: string | null;
|
||||
dueDate?: string | null;
|
||||
status?: string;
|
||||
effectivenessCheck?: string;
|
||||
@@ -237,7 +234,10 @@ export const useUpdateNonconformity = () => {
|
||||
|
||||
return promisifyMutation(mutate)({
|
||||
variables: {
|
||||
input,
|
||||
input: {
|
||||
...input,
|
||||
auditId: input.auditId || null,
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<a7d4ac5eee7f07fadad4e2c1f25e87e5>>
|
||||
* @generated SignedSource<<db7fca9f154989ebab9e5c9b0f5bfd85>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -11,7 +11,7 @@
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type NonconformityStatus = "CLOSED" | "IN_PROGRESS" | "OPEN";
|
||||
export type CreateNonconformityInput = {
|
||||
auditId: string;
|
||||
auditId?: string | null | undefined;
|
||||
correctiveAction?: string | null | undefined;
|
||||
dateIdentified?: any | null | undefined;
|
||||
description?: string | null | undefined;
|
||||
@@ -36,7 +36,7 @@ export type NonconformityGraphCreateMutation$data = {
|
||||
readonly name: string;
|
||||
};
|
||||
readonly id: string;
|
||||
};
|
||||
} | null | undefined;
|
||||
readonly createdAt: any;
|
||||
readonly dateIdentified: any | null | undefined;
|
||||
readonly description: string | null | undefined;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<125cf1d460b37ac442d0f30c14e5af11>>
|
||||
* @generated SignedSource<<526115183274c5c81a5a70c16012591e>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -21,7 +21,7 @@ export type NonconformityGraphNodeQuery$data = {
|
||||
readonly name: string;
|
||||
};
|
||||
readonly id: string;
|
||||
};
|
||||
} | null | undefined;
|
||||
readonly correctiveAction?: string | null | undefined;
|
||||
readonly createdAt?: any;
|
||||
readonly dateIdentified?: any | null | undefined;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<9c7a235f3dc4f691c8f9d036536cf272>>
|
||||
* @generated SignedSource<<2f4ca0549a2e01d68d9fb752298beb4c>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -35,7 +35,7 @@ export type NonconformityGraphUpdateMutation$data = {
|
||||
readonly name: string;
|
||||
};
|
||||
readonly id: string;
|
||||
};
|
||||
} | null | undefined;
|
||||
readonly correctiveAction: string | null | undefined;
|
||||
readonly dateIdentified: any | null | undefined;
|
||||
readonly description: string | null | undefined;
|
||||
|
||||
@@ -36,6 +36,7 @@ import { getAuditStateLabel, getAuditStateVariant, auditStates, fileSize, sprint
|
||||
import type { AuditGraphNodeQuery } from "/hooks/graph/__generated__/AuditGraphNodeQuery.graphql";
|
||||
import { use } from "react";
|
||||
import { PermissionsContext } from "/providers/PermissionsContext";
|
||||
import { useNavigate } from "react-router";
|
||||
|
||||
const updateAuditSchema = z.object({
|
||||
name: z.string().nullable().optional(),
|
||||
@@ -54,10 +55,12 @@ export default function AuditDetailsPage(props: Props) {
|
||||
const { __ } = useTranslate();
|
||||
const organizationId = useOrganizationId();
|
||||
const { isAuthorized } = use(PermissionsContext);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const deleteAudit = useDeleteAudit(
|
||||
{ id: auditEntry.id!, framework: { name: auditEntry.framework!.name} },
|
||||
ConnectionHandler.getConnectionID(organizationId, "AuditsPage_audits")
|
||||
ConnectionHandler.getConnectionID(organizationId, "AuditsPage_audits"),
|
||||
() => navigate(`/organizations/${organizationId}/audits`)
|
||||
);
|
||||
|
||||
const { control, formState, handleSubmit, register, reset } = useFormWithSchema(updateAuditSchema, {
|
||||
|
||||
@@ -273,9 +273,11 @@ function NonconformityRow({
|
||||
</Badge>
|
||||
</Td>
|
||||
<Td>
|
||||
{nonconformity.audit.name
|
||||
? `${nonconformity.audit.framework.name} - ${nonconformity.audit.name}`
|
||||
: nonconformity.audit.framework.name
|
||||
{nonconformity.audit
|
||||
? nonconformity.audit.name
|
||||
? `${nonconformity.audit.framework?.name} - ${nonconformity.audit.name}`
|
||||
: nonconformity.audit.framework?.name
|
||||
: <span className="text-txt-tertiary">{__("No audit")}</span>
|
||||
}
|
||||
</Td>
|
||||
<Td>{nonconformity.owner.fullName}</Td>
|
||||
|
||||
@@ -47,7 +47,7 @@ const updateNonconformitySchema = z.object({
|
||||
effectivenessCheck: z.string().optional(),
|
||||
status: z.enum(["OPEN", "IN_PROGRESS", "CLOSED"]),
|
||||
ownerId: z.string().min(1, "Owner is required"),
|
||||
auditId: z.string().min(1, "Audit is required"),
|
||||
auditId: z.string().optional(),
|
||||
});
|
||||
|
||||
type Props = {
|
||||
@@ -198,7 +198,6 @@ export default function NonconformityDetailsPage(props: Props) {
|
||||
name="auditId"
|
||||
label={__("Audit")}
|
||||
error={formState.errors.auditId?.message}
|
||||
required
|
||||
disabled={isSnapshotMode}
|
||||
/>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<b53ef2729d5b435baeb0d3b068be8cef>>
|
||||
* @generated SignedSource<<310dfd9974ac15af86b8e8ecf21d2b5c>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -24,7 +24,7 @@ export type NonconformitiesPageFragment$data = {
|
||||
};
|
||||
readonly id: string;
|
||||
readonly name: string | null | undefined;
|
||||
};
|
||||
} | null | undefined;
|
||||
readonly correctiveAction: string | null | undefined;
|
||||
readonly createdAt: any;
|
||||
readonly dateIdentified: any | null | undefined;
|
||||
|
||||
@@ -27,7 +27,7 @@ import { formatDatetime, getStatusOptions } from "@probo/helpers";
|
||||
const schema = z.object({
|
||||
referenceId: z.string().min(1, "Reference ID is required"),
|
||||
description: z.string().optional(),
|
||||
auditId: z.string().min(1, "Audit is required"),
|
||||
auditId: z.string().optional(),
|
||||
dateIdentified: z.string().optional(),
|
||||
rootCause: z.string().min(1, "Root cause is required"),
|
||||
correctiveAction: z.string().optional(),
|
||||
@@ -78,7 +78,7 @@ export function CreateNonconformityDialog({
|
||||
organizationId,
|
||||
referenceId: formData.referenceId,
|
||||
description: formData.description || undefined,
|
||||
auditId: formData.auditId,
|
||||
auditId: formData.auditId || undefined,
|
||||
dateIdentified: formatDatetime(formData.dateIdentified),
|
||||
rootCause: formData.rootCause,
|
||||
correctiveAction: formData.correctiveAction || undefined,
|
||||
@@ -128,7 +128,6 @@ export function CreateNonconformityDialog({
|
||||
name="auditId"
|
||||
label={__("Audit")}
|
||||
error={formState.errors.auditId?.message}
|
||||
required
|
||||
/>
|
||||
|
||||
<div className="space-y-2">
|
||||
|
||||
Reference in New Issue
Block a user