Skip to content

Commit 6af1aed

Browse files
committed
feat: implemented ui updates and new features
1 parent b8e1821 commit 6af1aed

File tree

25 files changed

+702
-230
lines changed

25 files changed

+702
-230
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,35 @@
11
import { useEffect, useState } from 'react';
22
import { buildUrl, handleDialogClose } from '../../utils/helpers';
33
import { serverFunctions } from '../../utils/serverFunctions';
4+
import useAuth from '../../hooks/useAuth';
5+
import { CircularProgress, Container, Typography } from '@mui/material';
46

5-
interface AuthState {
6-
authorized: boolean;
7-
token?: string;
8-
message?: string;
9-
}
10-
11-
type Status = 'idle' | 'loading' | 'success' | 'error';
12-
13-
const Dialog = () => {
7+
const CreateDiagramDialog = () => {
8+
const { authState, authStatus } = useAuth();
149
const [diagramsUrl, setDiagramsUrl] = useState('');
15-
const [, setAuthState] = useState<null | AuthState>(null);
16-
const [authStatus, setAuthStatus] = useState<Status>('idle');
1710

1811
useEffect(() => {
19-
const getAuth = async () => {
20-
setAuthStatus('loading');
21-
try {
22-
const state = await serverFunctions.getAuthorizationState();
23-
setAuthState(state);
24-
setAuthStatus('success');
25-
26-
if (state.authorized) {
27-
const url = buildUrl('/app/plugins/confluence/select', state.token);
28-
setDiagramsUrl(url);
29-
}
30-
} catch (error) {
31-
console.log('Error getting auth data', error);
32-
setAuthStatus('error');
33-
}
34-
};
35-
36-
getAuth();
37-
}, []);
12+
if (!authState?.authorized) return;
13+
// const url = buildUrl('/app/plugins/confluence/select', state.token);
14+
const url = buildUrl(
15+
'/app/diagrams/new?pluginSource=googledocs',
16+
authState.token
17+
);
18+
setDiagramsUrl(url);
19+
}, [authState]);
3820

3921
useEffect(() => {
4022
const handleMessage = async (e: MessageEvent) => {
4123
const action = e.data.action;
42-
console.log('action', action, e.data);
4324
if (action === 'save') {
4425
const data = e.data.data;
45-
console.log(data);
4626
const metadata = new URLSearchParams({
4727
projectID: data.projectID,
4828
documentID: data.documentID,
4929
major: data.major,
5030
minor: data.minor,
5131
});
32+
5233
try {
5334
await serverFunctions.insertBase64ImageWithMetadata(
5435
data.diagramImage,
@@ -68,8 +49,41 @@ const Dialog = () => {
6849
};
6950
}, []);
7051

71-
if (authStatus !== 'success') {
72-
return null;
52+
if (authStatus === 'idle' || authStatus === 'loading') {
53+
return (
54+
<Container
55+
sx={{
56+
display: 'flex',
57+
flexDirection: 'column',
58+
alignItems: 'center',
59+
justifyContent: 'center',
60+
height: '96.5vh',
61+
}}
62+
>
63+
<CircularProgress />
64+
</Container>
65+
);
66+
}
67+
68+
if (authStatus === 'error') {
69+
return (
70+
<Container
71+
sx={{
72+
display: 'flex',
73+
flexDirection: 'column',
74+
alignItems: 'center',
75+
justifyContent: 'center',
76+
height: '96.5vh',
77+
}}
78+
>
79+
<Typography variant="h5" gutterBottom my={2} textAlign="center">
80+
Error
81+
</Typography>
82+
<Typography paragraph textAlign="center">
83+
Something went wrong. Please try again later.
84+
</Typography>
85+
</Container>
86+
);
7387
}
7488

7589
return (
@@ -87,4 +101,4 @@ const Dialog = () => {
87101
);
88102
};
89103

90-
export default Dialog;
104+
export default CreateDiagramDialog;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import ReactDOM from 'react-dom';
2+
import CreateDiagramDialog from './components/create-diagram-dialog';
3+
import './styles.css';
4+
5+
ReactDOM.render(<CreateDiagramDialog />, document.getElementById('index'));

src/client/dialog/index.jsx

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/client/edit-dialog/components/EditDialog.tsx renamed to src/client/edit-diagram-dialog/components/edit-diagram-dialog.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ import { serverFunctions } from '../../utils/serverFunctions';
33
import { buildUrl, handleDialogClose } from '../../utils/helpers';
44
import useAuth from '../../hooks/useAuth';
55

6-
const EditDialog = () => {
6+
const EditDiagramDialog = () => {
77
const { authState, authStatus } = useAuth();
88
const [diagramsUrl, setDiagramsUrl] = useState('');
99

1010
useEffect(() => {
11-
if (!authState) return;
11+
if (!authState?.authorized) return;
12+
1213
const getMetadata = async () => {
1314
try {
1415
const metadata = await serverFunctions.readSelectedImageMetadata();
15-
console.log(metadata, 'metadata');
1616
if (typeof metadata === 'string') {
1717
const params = new URLSearchParams(metadata);
1818
const projectID = params.get('projectID');
1919
const documentID = params.get('documentID');
2020
const major = params.get('major');
2121
const minor = params.get('minor');
22-
if (projectID && documentID && major && minor && authState?.token) {
22+
if (projectID && documentID && major && minor) {
2323
const iframeUrl = buildUrl(
2424
`/app/projects/${projectID}/diagrams/${documentID}/version/v.${major}.${minor}/edit`,
2525
authState.token
@@ -31,6 +31,7 @@ const EditDialog = () => {
3131
console.log(error);
3232
}
3333
};
34+
3435
getMetadata();
3536
}, [authState]);
3637

@@ -84,4 +85,4 @@ const EditDialog = () => {
8485
);
8586
};
8687

87-
export default EditDialog;
88+
export default EditDiagramDialog;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import ReactDOM from 'react-dom';
2+
import EditDiagramDialog from './components/edit-diagram-dialog';
3+
4+
import './styles.css';
5+
6+
ReactDOM.render(<EditDiagramDialog />, document.getElementById('index'));

0 commit comments

Comments
 (0)