@@ -2,6 +2,7 @@ import { Excalidraw } from "@excalidraw/excalidraw";
22import { type ExcalidrawElement } from "@excalidraw/excalidraw/types/element/types" ;
33import { useMutation , useQuery } from "@tanstack/react-query" ;
44import { t } from "i18next" ;
5+ import { navigate } from "raviger" ;
56import { useEffect , useState } from "react" ;
67import { toast } from "sonner" ;
78
@@ -10,6 +11,7 @@ import { debounce } from "@/lib/utils";
1011import CareIcon from "@/CAREUI/icons/CareIcon" ;
1112
1213import { Button } from "@/components/ui/button" ;
14+ import { Input } from "@/components/ui/input" ;
1315
1416import Loading from "@/components/Common/Loading" ;
1517import { CreateFileResponse } from "@/components/Patient/models" ;
@@ -19,16 +21,22 @@ import mutate from "@/Utils/request/mutate";
1921import query from "@/Utils/request/query" ;
2022
2123type Props = {
22- patientId : string ;
24+ associatingId : string ;
25+ fileType : string ;
2326 drawingId ?: string ;
2427} ;
2528
26- export default function ExcalidrawPage ( { patientId, drawingId } : Props ) {
29+ export default function ExcalidrawPage ( {
30+ associatingId,
31+ drawingId,
32+ fileType,
33+ } : Props ) {
2734 const [ elements , setElements ] = useState < readonly ExcalidrawElement [ ] | null > (
2835 drawingId ? null : [ ] ,
2936 ) ;
3037 const [ name , setName ] = useState ( "" ) ;
3138 const [ id , setId ] = useState ( drawingId ) ;
39+ const [ isDirty , setIsDirty ] = useState ( false ) ;
3240
3341 const { data, isLoading } = useQuery ( {
3442 queryKey : [ "file" , id ] ,
@@ -37,7 +45,11 @@ export default function ExcalidrawPage({ patientId, drawingId }: Props) {
3745 } ) ,
3846 enabled : ! ! id ,
3947 } ) ;
40- console . log ( data ) ;
48+
49+ useEffect ( ( ) => {
50+ setIsDirty ( ! ! elements ?. length ) ;
51+ } , [ elements ?. length ] ) ;
52+
4153 useEffect ( ( ) => {
4254 if ( ! data ) {
4355 return ;
@@ -87,11 +99,11 @@ export default function ExcalidrawPage({ patientId, drawingId }: Props) {
8799 let response : CreateFileResponse | null = null ;
88100 if ( ! id ) {
89101 response = await createUpload ( {
90- original_name : name ,
102+ original_name : ` ${ name } .excalidraw` ,
91103 name : name ,
92- file_type : "patient" ,
104+ file_type : fileType ,
93105 file_category : "unspecified" ,
94- associating_id : patientId ,
106+ associating_id : associatingId ,
95107 mime_type : "text/plain" ,
96108 } ) ;
97109 signedUrl = response . signed_url ;
@@ -117,6 +129,7 @@ export default function ExcalidrawPage({ patientId, drawingId }: Props) {
117129 return ;
118130 } else {
119131 toast . success ( t ( "file_success__upload_complete" ) ) ;
132+ navigate ( `drawings/${ response ! . id } ` ) ;
120133 }
121134 } catch ( error ) {
122135 console . error ( "Error in Step 1 (createUpload):" , error ) ;
@@ -128,27 +141,29 @@ export default function ExcalidrawPage({ patientId, drawingId }: Props) {
128141 }
129142
130143 return (
131- < div className = "flex flex-col h-[calc(100vh-5rem )]" >
144+ < div className = "flex flex-col h-[calc(100vh-4rem )]" >
132145 < div className = "flex flex-row justify-between items-center p-2" >
133146 < div className = "flex flex-row items-center" >
134147 < div className = "rounded-full bg-primary-100 px-5 py-4" >
135148 < CareIcon icon = "l-pen" className = "text-lg text-primary-500" />
136149 </ div >
137150 < div className = "m-4" >
138- < input
151+ < Input
139152 type = "text"
140153 value = { name }
141154 placeholder = "Enter the File Name"
142155 onChange = { ( e ) => setName ( e . target . value ) }
143156 />
144157 </ div >
145158 </ div >
146- < Button className = "ml-auto" onClick = { handleSave } >
147- { t ( "save" ) }
148- </ Button >
159+ { isDirty && (
160+ < Button className = "ml-auto" onClick = { handleSave } >
161+ { t ( "save" ) }
162+ </ Button >
163+ ) }
149164 </ div >
150165
151- < div className = "flex-grow p -2" >
166+ < div className = "flex-grow h-[calc(100vh-10rem)] -m -2" >
152167 < Excalidraw
153168 UIOptions = { {
154169 canvasActions : {
@@ -158,7 +173,6 @@ export default function ExcalidrawPage({ patientId, drawingId }: Props) {
158173 } ,
159174 } }
160175 initialData = { {
161- elements : elements ,
162176 appState : { theme : "light" } ,
163177 } }
164178 onChange = { debounce ( async ( elements ) => {
0 commit comments