Learn how to seamlessly integrate Lovable with Time Doctor. Our step-by-step guide simplifies time tracking and boosts productivity for your team.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
This guide will walk you through integrating Time Doctor functionality into your Lovable project using TypeScript. Follow each step carefully and insert or create the indicated files and code snippets exactly as shown.
Since Lovable does not have a terminal to install dependencies, we will load Axios from a CDN. Open your main HTML file (usually named index.html) in your project and add the following script tag before your main application script:
Within your project’s file explorer, create a new folder named "integrations". Inside this folder, create a new file called timeDoctor.ts. Copy and paste the following code snippet into that file. This code defines functions to start and stop timers via the Time Doctor API:
// File: integrations/timeDoctor.ts
// We are assuming axios is available as a global variable since it was added via a CDN in index.html.
// If not available globally, you may need to adjust your configuration to support module imports.
const APIKEY: string = 'YOURTIMEDOCTORAPIKEY'; // Replace with your actual Time Doctor API key.
const API_ENDPOINT: string = 'https://webapi.timedoctor.com/v2.0/'; // Replace or adjust endpoint as needed.
export async function startTimer(taskId: string): Promise {
try {
const response = await axios.post(${API_ENDPOINT}start, {
taskId: taskId,
apiKey: API_KEY
});
return response.data;
} catch (error) {
console.error('Error starting timer:', error);
throw error;
}
}
export async function stopTimer(timerId: string): Promise {
try {
const response = await axios.post(${API_ENDPOINT}stop, {
timerId: timerId,
apiKey: API_KEY
});
return response.data;
} catch (error) {
console.error('Error stopping timer:', error);
throw error;
}
}
Open the main TypeScript file of your Lovable project (for example, app.ts or main.ts). At the top of this file, import the functions you defined in timeDoctor.ts. Then, use these functions in appropriate event handlers where you want to start or stop the Time Doctor timer (for instance, when a task starts or stops). Insert the following code snippet into your main application file:
// In your main application file, e.g., app.ts or main.ts
import { startTimer, stopTimer } from './integrations/timeDoctor';
// Example function to be called when a task starts.
function onTaskStart(taskId: string) {
startTimer(taskId)
.then(data => {
console.log('Timer started successfully:', data);
})
.catch(err => {
console.error('Failed to start timer:', err);
});
}
// Example function to be called when a task stops.
function onTaskStop(timerId: string) {
stopTimer(timerId)
.then(data => {
console.log('Timer stopped successfully:', data);
})
.catch(err => {
console.error('Failed to stop timer:', err);
});
}
// These function calls should be integrated with your Lovable project logic where tasks are started and stopped.
// For example, you might call onTaskStart(taskId) when a user begins a task, and onTaskStop(timerId) when the task ends.
After adding the above code, follow these guidelines to test your integration:
Once you confirm that the timer functions are working as expected, ensure the following in your Lovable project:
By following these steps, you have successfully integrated Time Doctor into your Lovable project using TypeScript without the need for a separate terminal installation.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.