diff --git a/apps/console/src/__generated__/core/DocumentDescriptionPage_updateContentMutation.graphql.ts b/apps/console/src/__generated__/core/DocumentDescriptionPage_updateContentMutation.graphql.ts new file mode 100644 index 000000000..09de067a5 --- /dev/null +++ b/apps/console/src/__generated__/core/DocumentDescriptionPage_updateContentMutation.graphql.ts @@ -0,0 +1,93 @@ +/** + * @generated SignedSource<<1f7c6a92ab7920b470a03799e04f4ea3>> + * @lightSyntaxTransform + * @nogrep + */ + +/* tslint:disable */ +/* eslint-disable */ +// @ts-nocheck + +import { ConcreteRequest } from 'relay-runtime'; +export type UpdateDocumentVersionContentInput = { + content: string; + id: string; +}; +export type DocumentDescriptionPage_updateContentMutation$variables = { + input: UpdateDocumentVersionContentInput; +}; +export type DocumentDescriptionPage_updateContentMutation$data = { + readonly updateDocumentVersionContent: { + readonly content: string; + }; +}; +export type DocumentDescriptionPage_updateContentMutation = { + response: DocumentDescriptionPage_updateContentMutation$data; + variables: DocumentDescriptionPage_updateContentMutation$variables; +}; + +const node: ConcreteRequest = (function(){ +var v0 = [ + { + "defaultValue": null, + "kind": "LocalArgument", + "name": "input" + } +], +v1 = [ + { + "alias": null, + "args": [ + { + "kind": "Variable", + "name": "input", + "variableName": "input" + } + ], + "concreteType": "UpdateDocumentVersionContentPayload", + "kind": "LinkedField", + "name": "updateDocumentVersionContent", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "content", + "storageKey": null + } + ], + "storageKey": null + } +]; +return { + "fragment": { + "argumentDefinitions": (v0/*: any*/), + "kind": "Fragment", + "metadata": null, + "name": "DocumentDescriptionPage_updateContentMutation", + "selections": (v1/*: any*/), + "type": "Mutation", + "abstractKey": null + }, + "kind": "Request", + "operation": { + "argumentDefinitions": (v0/*: any*/), + "kind": "Operation", + "name": "DocumentDescriptionPage_updateContentMutation", + "selections": (v1/*: any*/) + }, + "params": { + "cacheID": "2a43a5cf619ca1d475b3e480a132878b", + "id": null, + "metadata": {}, + "name": "DocumentDescriptionPage_updateContentMutation", + "operationKind": "mutation", + "text": "mutation DocumentDescriptionPage_updateContentMutation(\n $input: UpdateDocumentVersionContentInput!\n) {\n updateDocumentVersionContent(input: $input) {\n content\n }\n}\n" + } +}; +})(); + +(node as any).hash = "2bfee42c8fe67762416dec052c5f051b"; + +export default node; diff --git a/apps/console/src/hooks/forms/useDocumentForm.tsx b/apps/console/src/hooks/forms/useDocumentForm.tsx deleted file mode 100644 index d5b0590df..000000000 --- a/apps/console/src/hooks/forms/useDocumentForm.tsx +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2025-2026 Probo Inc . -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -import { z } from "zod"; - -import { useFormWithSchema } from "../useFormWithSchema"; - -export const documentSchema = z.object({ - title: z.string().min(1, "Title is required"), - content: z.string().min(1, "Content is required"), - documentType: z.enum(["OTHER", "GOVERNANCE", "POLICY", "PROCEDURE", "PLAN", "REGISTER", "RECORD", "REPORT", "TEMPLATE"]), - classification: z.enum(["PUBLIC", "INTERNAL", "CONFIDENTIAL", "SECRET"]), -}); - -export const useDocumentForm = () => { - return useFormWithSchema(documentSchema, { - defaultValues: { - documentType: "POLICY", - classification: "INTERNAL", - }, - }); -}; diff --git a/apps/console/src/pages/organizations/documents/_components/CreateDocumentDialog.tsx b/apps/console/src/pages/organizations/documents/_components/CreateDocumentDialog.tsx index 26c5bf1bb..f99d5801d 100644 --- a/apps/console/src/pages/organizations/documents/_components/CreateDocumentDialog.tsx +++ b/apps/console/src/pages/organizations/documents/_components/CreateDocumentDialog.tsx @@ -23,18 +23,17 @@ import { Input, Label, PropertyRow, - Textarea, useDialogRef, } from "@probo/ui"; import { type ReactNode } from "react"; import { graphql } from "relay-runtime"; -import type { z } from "zod"; +import { z } from "zod"; import type { CreateDocumentDialogMutation } from "#/__generated__/core/CreateDocumentDialogMutation.graphql"; import { ControlledField } from "#/components/form/ControlledField"; import { DocumentClassificationOptions } from "#/components/form/DocumentClassificationOptions"; import { DocumentTypeOptions } from "#/components/form/DocumentTypeOptions"; -import { documentSchema, useDocumentForm } from "#/hooks/forms/useDocumentForm"; +import { useFormWithSchema } from "#/hooks/useFormWithSchema"; import { useMutationWithToasts } from "#/hooks/useMutationWithToasts"; import { useOrganizationId } from "#/hooks/useOrganizationId"; @@ -65,6 +64,13 @@ const createDocumentMutation = graphql` } `; +const documentSchema = z.object({ + title: z.string().min(1, "Title is required"), + approverIds: z.array(z.string()).min(1, "At least one approver is required"), + documentType: z.enum(["OTHER", "GOVERNANCE", "POLICY", "PROCEDURE", "PLAN", "REGISTER", "RECORD", "REPORT", "TEMPLATE"]), + classification: z.enum(["PUBLIC", "INTERNAL", "CONFIDENTIAL", "SECRET"]), +}); + /** * Dialog to create or update a document */ @@ -72,8 +78,15 @@ export function CreateDocumentDialog({ trigger, connection }: Props) { const { __ } = useTranslate(); const organizationId = useOrganizationId(); - const { control, handleSubmit, register, formState, reset } - = useDocumentForm(); + const { control, handleSubmit, register, formState, reset } = useFormWithSchema( + documentSchema, + { + defaultValues: { + documentType: "POLICY", + classification: "INTERNAL", + }, + }, + ); const errors = formState.errors ?? {}; const [createDocument, isLoading] = useMutationWithToasts(createDocumentMutation); @@ -115,14 +128,6 @@ export function CreateDocumentDialog({ trigger, connection }: Props) { placeholder={__("Document title")} {...register("title")} /> -