Implementing Contract creation on draft page
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
from beanie import PydanticObjectId
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from firm.contract.models import ContractDraft, DraftProvision, DraftParty, Contract
|
from firm.contract.models import ContractDraft, DraftProvision, DraftParty, Contract
|
||||||
|
|
||||||
from firm.entity.models import Entity
|
from firm.entity.models import Entity
|
||||||
from firm.core.schemas import Writer, Reader
|
from firm.core.schemas import Writer, Reader
|
||||||
from firm.core.models import DictionaryEntry
|
from firm.core.models import DictionaryEntry, ForeignKey
|
||||||
|
|
||||||
|
|
||||||
class ContractDraftRead(Reader, ContractDraft):
|
class ContractDraftRead(Reader, ContractDraft):
|
||||||
@@ -68,7 +69,7 @@ class ContractRead(Reader, Contract):
|
|||||||
class ContractCreate(Writer):
|
class ContractCreate(Writer):
|
||||||
date: datetime.date
|
date: datetime.date
|
||||||
location: str
|
location: str
|
||||||
draft_id: str
|
draft_id: PydanticObjectId = ForeignKey(resource="contracts/drafts", schema="ContractDraft")
|
||||||
|
|
||||||
class ContractInit(BaseModel):
|
class ContractInit(BaseModel):
|
||||||
date: datetime.date
|
date: datetime.date
|
||||||
|
|||||||
1
gui/rpk-gui/package-lock.json
generated
1
gui/rpk-gui/package-lock.json
generated
@@ -35,6 +35,7 @@
|
|||||||
"@tiptap/extension-underline": "^2.11.7",
|
"@tiptap/extension-underline": "^2.11.7",
|
||||||
"@tiptap/react": "^2.11.7",
|
"@tiptap/react": "^2.11.7",
|
||||||
"@tiptap/starter-kit": "^2.11.7",
|
"@tiptap/starter-kit": "^2.11.7",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
"i18next": "^25.0.1",
|
"i18next": "^25.0.1",
|
||||||
"i18next-browser-languagedetector": "^8.0.5",
|
"i18next-browser-languagedetector": "^8.0.5",
|
||||||
"i18next-http-backend": "^3.0.2",
|
"i18next-http-backend": "^3.0.2",
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
"@tiptap/extension-underline": "^2.11.7",
|
"@tiptap/extension-underline": "^2.11.7",
|
||||||
"@tiptap/react": "^2.11.7",
|
"@tiptap/react": "^2.11.7",
|
||||||
"@tiptap/starter-kit": "^2.11.7",
|
"@tiptap/starter-kit": "^2.11.7",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
"i18next": "^25.0.1",
|
"i18next": "^25.0.1",
|
||||||
"i18next-browser-languagedetector": "^8.0.5",
|
"i18next-browser-languagedetector": "^8.0.5",
|
||||||
"i18next-http-backend": "^3.0.2",
|
"i18next-http-backend": "^3.0.2",
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { Route, Routes } from "react-router";
|
import { Route, Routes } from "react-router";
|
||||||
import List from "./base-page/List";
|
import List from "./base-page/List";
|
||||||
import Edit from "./base-page/Edit";
|
import Edit from "./base-page/Edit";
|
||||||
import New from "./base-page/New";
|
|
||||||
|
|
||||||
type Contract = {
|
export type Contract = {
|
||||||
id: string,
|
id: string,
|
||||||
label: string
|
label: string
|
||||||
}
|
}
|
||||||
@@ -13,7 +12,6 @@ export const ContractRoutes = () => {
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route index element={ <ListContract /> } />
|
<Route index element={ <ListContract /> } />
|
||||||
<Route path="/edit/:record_id" element={ <EditContract /> } />
|
<Route path="/edit/:record_id" element={ <EditContract /> } />
|
||||||
<Route path="/create" element={ <CreateContract /> } />
|
|
||||||
</Routes>
|
</Routes>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -28,7 +26,3 @@ const ListContract = () => {
|
|||||||
const EditContract = () => {
|
const EditContract = () => {
|
||||||
return <Edit<Contract> resource={`contracts`} schemaName={"Contract"} />
|
return <Edit<Contract> resource={`contracts`} schemaName={"Contract"} />
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateContract = () => {
|
|
||||||
return <New<Contract> resource={`contracts`} schemaName={"Contract"} />
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Route, Routes } from "react-router";
|
import { Navigate, Route, Routes, useParams } from "react-router";
|
||||||
import { CircularProgress } from "@mui/material";
|
import { CircularProgress } from "@mui/material";
|
||||||
import React, { useContext, useState } from "react";
|
import React, { useContext, useState } from "react";
|
||||||
import { useOne } from "@refinedev/core";
|
import { useOne, useTranslation } from "@refinedev/core";
|
||||||
import { BaseForm } from "../../lib/crud/components/base-form";
|
import { BaseForm } from "../../lib/crud/components/base-form";
|
||||||
import { ForeignKeyReference, ForeignKeySchema } from "../../lib/crud/components/widgets/foreign-key";
|
import { ForeignKeyReference, ForeignKeySchema } from "../../lib/crud/components/widgets/foreign-key";
|
||||||
|
|
||||||
@@ -9,6 +9,8 @@ import { FirmContext } from "../../contexts/FirmContext";
|
|||||||
import List from "./base-page/List";
|
import List from "./base-page/List";
|
||||||
import Edit from "./base-page/Edit";
|
import Edit from "./base-page/Edit";
|
||||||
import New from "./base-page/New";
|
import New from "./base-page/New";
|
||||||
|
import { Contract } from "./ContractRoutes";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
type Draft = {
|
type Draft = {
|
||||||
id: string,
|
id: string,
|
||||||
@@ -33,7 +35,63 @@ const ListDraft = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const EditDraft = () => {
|
const EditDraft = () => {
|
||||||
return <Edit<Draft> resource={`contracts/drafts`} schemaName={"ContractDraft"} />
|
const { currentFirm } = useContext(FirmContext);
|
||||||
|
const { record_id } = useParams();
|
||||||
|
const resourceBasePath = `firm/${currentFirm.instance}/${currentFirm.firm}`
|
||||||
|
|
||||||
|
const { data, isLoading } = useOne({
|
||||||
|
resource: `${resourceBasePath}/contracts/drafts`,
|
||||||
|
id: record_id
|
||||||
|
})
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <CircularProgress />
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data?.data) {
|
||||||
|
return <Navigate to="../" />
|
||||||
|
}
|
||||||
|
|
||||||
|
const draft = data?.data
|
||||||
|
const readOnly = draft.status === "published";
|
||||||
|
|
||||||
|
const uiSchema = {
|
||||||
|
"ui:readonly": readOnly
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Edit<Draft> resource={"contracts/drafts"} schemaName={"ContractDraft"} uiSchema={uiSchema} />
|
||||||
|
<ContractCreate draft={draft}></ContractCreate>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ContractCreate = (props: { draft: any}) => {
|
||||||
|
const { translate: t } = useTranslation();
|
||||||
|
const { draft } = props;
|
||||||
|
|
||||||
|
if (draft.status === "published") {
|
||||||
|
return <h4>{t("resource.draft.already_published") }</h4>
|
||||||
|
}
|
||||||
|
if (draft.status === "in_progress") {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h4>{ t("resource.draft.todo") + ":" }</h4>
|
||||||
|
<ul>{ draft.todo.map((item: any) => <li>{ item }</li>) }</ul>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return <New<Contract>
|
||||||
|
resource={"contracts"}
|
||||||
|
schemaName={"Contract"}
|
||||||
|
defaultValue={{
|
||||||
|
date: dayjs().format("YYYY-MM-DD"),
|
||||||
|
location: "Los Santos, SA",
|
||||||
|
draft_id: draft.id
|
||||||
|
}}
|
||||||
|
uiSchema={{ draft_id: { 'ui:widget': 'hidden' } }}
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
|
|
||||||
type ForeignKeySubSchema = ForeignKeySchema & {
|
type ForeignKeySubSchema = ForeignKeySchema & {
|
||||||
|
|||||||
Reference in New Issue
Block a user