aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/TaskBox.tsx
diff options
context:
space:
mode:
authorSkitty1238 <157652284+Skitty1238@users.noreply.github.com>2025-06-04 18:28:35 -0400
committerSkitty1238 <157652284+Skitty1238@users.noreply.github.com>2025-06-04 18:28:35 -0400
commit09be9002b5aa8f5ad7c602bcef6b53bbe0398cd3 (patch)
tree730acef57ae76d8698c68acb641fce3167d9c941 /src/client/views/nodes/TaskBox.tsx
parent645df1d00f953524c6da22103d26c38ae4331cd6 (diff)
fixed google authentication + linking and task creation via GT button
Diffstat (limited to 'src/client/views/nodes/TaskBox.tsx')
-rw-r--r--src/client/views/nodes/TaskBox.tsx57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/client/views/nodes/TaskBox.tsx b/src/client/views/nodes/TaskBox.tsx
index 3990356b9..8855e43c8 100644
--- a/src/client/views/nodes/TaskBox.tsx
+++ b/src/client/views/nodes/TaskBox.tsx
@@ -6,6 +6,7 @@ import { DocumentType } from '../../documents/DocumentTypes';
import { FieldView } from './FieldView';
import { DateField } from '../../../fields/DateField';
import { Doc } from '../../../fields/Doc';
+import { Networking } from '../../Network';
import './TaskBox.scss';
import { GoogleAuthenticationManager } from '../../apis/GoogleAuthenticationManager';
@@ -270,7 +271,7 @@ export class TaskBox extends React.Component<TaskBoxProps> {
)}
{/** test button */}
- <button
+ {/* <button
className="task-manager-google"
onClick={async () => {
console.log('GT button clicked');
@@ -301,6 +302,60 @@ export class TaskBox extends React.Component<TaskBoxProps> {
}
}}>
GT
+ </button> */}
+
+ {/* <button
+ className="task-manager-google"
+ onClick={async () => {
+ console.log('GT button clicked');
+ const url = await Networking.FetchFromServer('/readGoogleAccessToken');
+ console.log('🔗 Redirecting to Google auth:', url);
+ window.location.href = url; // Redirect user to authenticate
+ }}
+ >
+ GT
+ </button> */}
+
+ <button
+ className="task-manager-google"
+ onClick={async event => {
+ event.preventDefault();
+
+ console.log('GT button clicked');
+ try {
+ const token = await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken();
+ console.log('Got token', token);
+
+ const response = await fetch('/googleTasks/create', {
+ method: 'POST',
+ credentials: 'include',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: `Bearer ${token}`,
+ },
+ body: JSON.stringify({
+ title: taskTitle || 'Untitled Task',
+ notes: taskDesc,
+ due: allDay ? String(doc.$task_dateRange)?.split('|')[0] + 'T23:59:00Z' : (doc.$task_endTime instanceof DateField && doc.$task_endTime.date?.toISOString()) || undefined,
+ status: doc.$task_completed ? 'completed' : 'needsAction',
+ completed: doc.$task_completed ? new Date().toISOString() : undefined,
+ }),
+ });
+
+ const result = await response.json();
+ console.log('Google Task result:', result);
+
+ if (result?.id) {
+ alert('✅ Task sent to Google Tasks!');
+ } else {
+ alert(`❌ Failed: ${result?.error?.message || 'Unknown error'}`);
+ }
+ } catch (err) {
+ console.error('Fetch error:', err);
+ alert('❌ Task creation failed.');
+ }
+ }}>
+ GT
</button>
</div>
);