add importer wizard with guided steps for each type

This commit is contained in:
Gregor Vostrak
2026-11-26 14:10:50 +01:00
committed by Constantin Graf
parent 8c19e5dac2
commit fdef90d92e
26 changed files with 2443 additions and 346 deletions

View File

@@ -1,58 +1,396 @@
import { expect, test } from '../playwright/fixtures';
import { PLAYWRIGHT_BASE_URL } from '../playwright/config';
import type { Page } from '@playwright/test';
import fs from 'fs';
import path from 'path';
async function goToImportExport(page: Page) {
await page.goto(PLAYWRIGHT_BASE_URL + '/import');
await expect(page.getByTestId('import_view')).toBeVisible({ timeout: 10000 });
}
test('test that import page loads with type dropdown and file upload', async ({ page }) => {
/**
* Uploads the file in the current wizard step and waits until the import was accepted.
* The import is processed in the background, the wizard polls it until it is finished.
*/
async function importFileInCurrentStep(page: Page, testFile: string) {
await Promise.all([
page.waitForResponse(
(response) =>
response.url().includes('/import') &&
response.request().method() === 'POST' &&
response.status() === 202,
{ timeout: 30000 }
),
page
.getByTestId('import_file_input')
.setInputFiles(path.resolve('resources/testfiles/' + testFile)),
]);
}
test('test that import page shows the import sources and the export', async ({ page }) => {
await goToImportExport(page);
await expect(page.getByTestId('import_view')).toBeVisible({ timeout: 10000 });
// Import section
await expect(page.getByRole('heading', { name: 'Import Data' })).toBeVisible();
await expect(page.locator('#importType')).toBeVisible();
for (const source of ['toggl', 'clockify', 'harvest', 'solidtime', 'generic']) {
await expect(page.getByTestId(`import_source_${source}`)).toBeVisible();
}
// Export section
await expect(page.getByRole('heading', { name: 'Export Data' })).toBeVisible();
await expect(page.getByRole('button', { name: 'Export Organization Data' })).toBeVisible();
});
test('test that selecting an import type shows instructions', async ({ page }) => {
test('test that every step of the import wizard can be skipped and gone back to', async ({
page,
}) => {
await goToImportExport(page);
const wizard = page.getByTestId('import_wizard');
const back = page.getByTestId('import_wizard_back');
const next = page.getByTestId('import_wizard_next');
// Select a Toggl import type
await page.getByLabel('Import Type').selectOption({ index: 1 });
// Preparation
await page.getByTestId('import_source_toggl').click();
await expect(wizard).toContainText('Before you export from');
await expect(wizard).toContainText('Sign in to Toggl as an Admin of the workspace');
await expect(next).toHaveText('Continue');
// Instructions should appear
await expect(page.getByText('Instructions:')).toBeVisible();
// Step 1: workspace data
await next.click();
await expect(wizard).toContainText('Step 2 of 3');
await expect(wizard).toContainText('Export the workspace data');
await expect(wizard).toContainText('Choose the ZIP file');
await expect(next).toHaveText('Skip');
// Skipping a required step without an import asks first, "Go back" stays on the step
const skipConfirm = page.getByTestId('import_wizard_skip_confirm');
await next.click();
await expect(page.getByText('Skip without importing?')).toBeVisible();
// Earlier steps have to be imported first, a later import does not update existing data
await expect(page.getByText('Import it before the next steps')).toBeVisible();
await page.getByRole('button', { name: 'Go back' }).click();
await expect(page.getByText('Skip without importing?')).toBeHidden();
await expect(wizard).toContainText('Step 2 of 3');
// Step 2: time entries
await next.click();
await skipConfirm.click();
await expect(wizard).toContainText('Step 3 of 3');
await expect(wizard).toContainText('Export the time entries');
await expect(wizard).toContainText('Choose the CSV file');
await expect(next).toHaveText('Skip and finish');
// Summary: nothing was imported, the last step can be imported later
await next.click();
await expect(page.getByText('You can come back to it later.')).toBeVisible();
await skipConfirm.click();
await expect(wizard).toContainText('Summary');
await expect(wizard.getByText('Not imported.')).toHaveCount(2);
await expect(next).toHaveText('Import from another tool');
// "Go to step" jumps back to a skipped step
await wizard.getByRole('button', { name: 'Go to step' }).first().click();
await expect(wizard).toContainText('Step 2 of 3');
// Back goes through all screens back to the source picker
await next.click();
await skipConfirm.click();
await expect(wizard).toContainText('Step 3 of 3');
await back.click();
await expect(wizard).toContainText('Step 2 of 3');
await back.click();
await expect(wizard).toContainText('Before you export from');
await back.click();
await expect(page.getByTestId('import_source_toggl')).toBeVisible();
await expect(back).not.toBeVisible();
// Change source switches to another tool
await page.getByTestId('import_source_harvest').click();
await next.click();
await expect(wizard).toContainText('Step 2 of 4');
await expect(wizard).toContainText('Export the clients');
await wizard.getByRole('button', { name: 'Change source' }).click();
await page.getByTestId('import_source_clockify').click();
await expect(wizard).toContainText('Clockify');
await expect(wizard).toContainText('Before you export from');
});
test('test that importing without selecting type shows error', async ({ page }) => {
test('test that importing a generic time entries CSV works through the wizard', async ({
page,
}) => {
// The imports are processed in the background and polled
test.slow();
await goToImportExport(page);
const wizard = page.getByTestId('import_wizard');
const next = page.getByTestId('import_wizard_next');
// Click Import Data without selecting a type
await page.getByRole('button', { name: 'Import Data' }).click();
await page.getByTestId('import_source_generic').click();
await next.click();
// Skip the projects
await expect(wizard).toContainText('Export the projects');
await next.click();
await page.getByTestId('import_wizard_skip_confirm').click();
await expect(wizard).toContainText('Export the time entries');
// Should show an error notification
await expect(page.getByText('Please select the import type')).toBeVisible();
await importFileInCurrentStep(page, 'generic_time_entries_import_test_1.csv');
// The CSV has 2 time entries, 2 projects, 1 client and 1 task
const stepImports = page.getByTestId('import_step_imports');
await expect(stepImports).toContainText(
'Created 2 time entries, 2 projects, 1 client, 1 task',
{ timeout: 30000 }
);
await expect(next).toHaveText('Finish');
// The import is listed in the summary and, once the source is closed, in the recent imports
await next.click();
await expect(wizard).toContainText('Summary');
await expect(wizard).toContainText('Created 2 time entries, 2 projects, 1 client, 1 task');
await expect(page.getByTestId('recent_imports')).toBeHidden();
await wizard.getByRole('button', { name: 'Change source' }).click();
await expect(page.getByTestId('recent_imports')).toContainText('Generic Time Entries');
await expect(page.getByTestId('recent_imports')).toContainText('Completed');
// The import created the projects, they are available in the app right away
await page.goto(PLAYWRIGHT_BASE_URL + '/projects');
await expect(page.getByTestId('projects_view')).toBeVisible({ timeout: 10000 });
await expect(page.getByTestId('project_table')).toContainText('Project without Client');
});
test('test that importing without selecting file shows error', async ({ page }) => {
test('test that a failed import is shown in the step and the step can be retried', async ({
page,
}) => {
// The imports are processed in the background and polled
test.slow();
await goToImportExport(page);
const next = page.getByTestId('import_wizard_next');
// Select an import type first
await page.getByLabel('Import Type').selectOption({ index: 1 });
await page.getByTestId('import_source_generic').click();
await next.click();
await next.click();
await page.getByTestId('import_wizard_skip_confirm').click();
// Click Import Data without selecting a file
await page.getByRole('button', { name: 'Import Data' }).click();
// A Clockify export is not a valid generic CSV
await importFileInCurrentStep(page, 'clockify_projects_import_test_1.csv');
await expect(page.getByTestId('import_step_imports')).toContainText(
'Failed, nothing was imported.',
{ timeout: 30000 }
);
// Should show an error notification
// The step is not done, it can be skipped or another file can be imported
await expect(next).toHaveText('Skip and finish');
await expect(page.getByTestId('import_file_input')).toBeEnabled();
await importFileInCurrentStep(page, 'generic_time_entries_import_test_1.csv');
await expect(page.getByTestId('import_step_imports')).toContainText('Created 2 time entries', {
timeout: 30000,
});
await expect(next).toHaveText('Finish');
});
test('test that the wizard continues with the next step of a source after reloading', async ({
page,
}) => {
// The imports are processed in the background and polled
test.slow();
await goToImportExport(page);
const wizard = page.getByTestId('import_wizard');
const next = page.getByTestId('import_wizard_next');
await page.getByTestId('import_source_clockify').click();
await next.click();
await expect(wizard).toContainText('Export the projects');
await importFileInCurrentStep(page, 'clockify_projects_import_test_1.csv');
await expect(page.getByTestId('import_step_imports')).toContainText('Created', {
timeout: 30000,
});
await expect(next).toHaveText('Next');
// After a reload the source picker suggests the next step of Clockify
await goToImportExport(page);
const suggestion = page.getByTestId('import_continue_suggestion');
await expect(suggestion).toContainText('Continue with Clockify');
await expect(suggestion).toContainText('Time entries');
await suggestion.click();
await expect(wizard).toContainText('Step 3 of 3');
await expect(wizard).toContainText('Export the time entries');
// Opening the source again also skips the imported step
await wizard.getByRole('button', { name: 'Change source' }).click();
await page.getByTestId('import_source_clockify').click();
await expect(wizard).toContainText('Step 3 of 3');
});
test('test that a running import opens its step and does not block the navigation', async ({
page,
}) => {
// Imports finish within seconds in the tests, so the running import is simulated
const runningImport = {
id: '9d6b4cf1-6c11-4b6d-9f58-3e8e4f4b2a10',
type: 'clockify_time_entries',
source: 'web',
status: 'running',
report: null,
error_message: null,
user_id: null,
started_at: new Date().toISOString(),
finished_at: null,
created_at: new Date().toISOString(),
};
await page.route(/\/api\/v1\/organizations\/[^/]+\/imports(\?.*)?$/, async (route) => {
const response = await route.fetch();
const json = await response.json();
json.data = [runningImport, ...json.data];
await route.fulfill({ response, json });
});
await page.route(`**/imports/${runningImport.id}`, (route) =>
route.fulfill({ json: { data: runningImport } })
);
await goToImportExport(page);
const wizard = page.getByTestId('import_wizard');
// The step of the running import is opened, no other file can be added until it has finished
await expect(wizard).toContainText('Clockify');
await expect(wizard).toContainText('Step 3 of 3');
await expect(page.getByTestId('import_step_imports')).toContainText('Importing…');
await expect(page.getByTestId('import_file_input')).toBeDisabled();
await expect(wizard).toContainText('Another import is running');
// Navigation still works, the running import is shown in a banner on the other screens
await page.getByTestId('import_wizard_back').click();
await expect(wizard).toContainText('Step 2 of 3');
await expect(page.getByTestId('import_in_progress')).toBeVisible();
// Skipping the projects asks first and names what would be missing
await page.getByTestId('import_wizard_next').click();
await expect(
page.getByText('Please select the CSV or ZIP file that you want to import')
page.getByText('Billable rates, billable status and estimates of the projects')
).toBeVisible();
await page.getByTestId('import_wizard_skip_confirm').click();
await expect(wizard).toContainText('Step 3 of 3');
await page.getByTestId('import_wizard_next').click();
await expect(wizard).toContainText('Summary');
await wizard.getByRole('button', { name: 'Change source' }).click();
await page.getByTestId('import_source_toggl').click();
await expect(page.getByTestId('import_in_progress')).toBeVisible();
await page.getByTestId('import_in_progress').getByRole('button', { name: 'Show' }).click();
await expect(wizard).toContainText('Clockify');
await expect(wizard).toContainText('Step 3 of 3');
await expect(page.getByTestId('recent_imports')).toBeHidden();
await wizard.getByRole('button', { name: 'Change source' }).click();
await expect(page.getByTestId('recent_imports')).toContainText('In progress');
});
test('test that a step with one file per year takes several files', async ({ page }) => {
// The imports are processed in the background and polled
test.slow();
await goToImportExport(page);
const wizard = page.getByTestId('import_wizard');
const next = page.getByTestId('import_wizard_next');
const stepImports = page.getByTestId('import_step_imports');
await page.getByTestId('import_source_toggl').click();
await next.click();
await next.click();
await page.getByTestId('import_wizard_skip_confirm').click();
await expect(wizard).toContainText('Export the time entries');
await importFileInCurrentStep(page, 'toggl_time_entries_import_test_1.csv');
await expect(stepImports).toContainText('Created', { timeout: 30000 });
// The step asks for the next year's file instead of offering to import the same file again
await expect(wizard).toContainText('Add the next file');
await expect(next).toHaveText('Finish');
await importFileInCurrentStep(page, 'toggl_time_entries_import_test_2.csv');
await expect(stepImports.getByText(/^Created/)).toHaveCount(2, { timeout: 30000 });
// Both files are listed in the summary
await next.click();
await expect(wizard).toContainText('Summary');
await expect(wizard.getByText(/^Created/)).toHaveCount(2);
});
test('test that every Harvest step can be imported and the source reopens at the summary', async ({
page,
}) => {
// The imports are processed in the background and polled
test.slow();
await goToImportExport(page);
const wizard = page.getByTestId('import_wizard');
const next = page.getByTestId('import_wizard_next');
const stepImports = page.getByTestId('import_step_imports');
await page.getByTestId('import_source_harvest').click();
await expect(wizard).toContainText('Sign in to Harvest as an Administrator');
await next.click();
await expect(wizard).toContainText('Export the clients');
await importFileInCurrentStep(page, 'harvest_clients_import_test_1.csv');
await expect(stepImports).toContainText('Created', { timeout: 30000 });
await expect(next).toHaveText('Next');
await next.click();
await expect(wizard).toContainText('Export the projects');
await importFileInCurrentStep(page, 'harvest_projects_import_test_1.csv');
await expect(stepImports).toContainText('Created', { timeout: 30000 });
await expect(next).toHaveText('Next');
await next.click();
await expect(wizard).toContainText('Export the time entries');
await importFileInCurrentStep(page, 'harvest_time_entries_import_test_1.csv');
await expect(stepImports).toContainText('Created', { timeout: 30000 });
await expect(next).toHaveText('Finish');
await next.click();
await expect(wizard).toContainText('Summary');
await expect(wizard).toContainText('Import from Harvest done');
await expect(wizard.getByText('Not imported.')).toHaveCount(0);
// A source with every step imported opens at the summary
await wizard.getByRole('button', { name: 'Change source' }).click();
await page.getByTestId('import_source_harvest').click();
await expect(wizard).toContainText('Import from Harvest done');
});
test('test that a file can be dropped on the upload area', async ({ page }) => {
// The imports are processed in the background and polled
test.slow();
await goToImportExport(page);
const wizard = page.getByTestId('import_wizard');
await page.getByTestId('import_source_generic').click();
await page.getByTestId('import_wizard_next').click();
await expect(wizard).toContainText('Export the projects');
const fileName = 'generic_projects_import_test_1.csv';
const content = fs.readFileSync(path.resolve('resources/testfiles/' + fileName), 'utf8');
const dataTransfer = await page.evaluateHandle(
({ content, fileName }) => {
const transfer = new DataTransfer();
transfer.items.add(new File([content], fileName, { type: 'text/csv' }));
return transfer;
},
{ content, fileName }
);
await Promise.all([
page.waitForResponse(
(response) =>
response.url().includes('/import') &&
response.request().method() === 'POST' &&
response.status() === 202,
{ timeout: 30000 }
),
page
.locator('label', { has: page.getByTestId('import_file_input') })
.dispatchEvent('drop', { dataTransfer }),
]);
await expect(page.getByTestId('import_step_imports')).toContainText(
'Created 3 projects, 2 clients',
{
timeout: 30000,
}
);
});
test('test that export button triggers export and shows success modal', async ({ page }) => {
@@ -87,59 +425,6 @@ test('test that export button triggers export and shows success modal', async ({
await expect(page.getByRole('button', { name: 'Download' }).first()).toBeVisible();
});
test('test that import type dropdown has multiple options', async ({ page }) => {
await goToImportExport(page);
// The dropdown should load with options from the API
await page.waitForResponse(
(response) =>
response.url().includes('/importers') &&
response.request().method() === 'GET' &&
response.status() === 200
);
// Verify the select has options besides the default placeholder
const options = page.getByLabel('Import Type').locator('option');
const count = await options.count();
// Should have at least the placeholder + some import types
expect(count).toBeGreaterThan(1);
});
test('test that importing a generic time entries CSV works', async ({ page }) => {
await goToImportExport(page);
await expect(page.getByTestId('import_view')).toBeVisible({ timeout: 10000 });
// Select "Generic Time Entries" import type
await page.getByLabel('Import Type').selectOption({ label: 'Generic Time Entries' });
await expect(page.getByText('Instructions:')).toBeVisible();
// Upload the test CSV file
const csvPath = path.resolve('resources/testfiles/generic_time_entries_import_test_1.csv');
await page.locator('#file-upload').setInputFiles(csvPath);
// Click Import and wait for the API response, the import is queued and processed in the background
await Promise.all([
page.waitForResponse(
(response) =>
response.url().includes('/import') &&
response.request().method() === 'POST' &&
response.status() === 202,
{ timeout: 30000 }
),
page.getByRole('button', { name: 'Import Data' }).click(),
]);
// Verify success modal with import results
await expect(page.getByRole('heading', { name: 'Import Result' })).toBeVisible();
await expect(page.getByText('The import was successful!')).toBeVisible();
// The CSV has 2 time entries, 1 client, 2 projects, 1 task
await expect(page.getByText('Time entries created:').locator('..')).toContainText('2');
await expect(page.getByText('Projects created:').locator('..')).toContainText('2');
await expect(page.getByText('Clients created:').locator('..')).toContainText('1');
await expect(page.getByText('Tasks created:').locator('..')).toContainText('1');
});
// =============================================
// Employee Permission Tests
// =============================================

View File

@@ -0,0 +1,29 @@
<script setup lang="ts">
import { GlobeAltIcon } from '@heroicons/vue/24/outline';
import ClockifySelect from './ClockifySelect.vue';
</script>
<template>
<div
role="img"
aria-label="Clockify preferences with the language English, the date format MM/DD/YYYY and the time format 12-hour"
class="w-full max-w-md rounded-lg border border-card-border bg-card-background px-4 py-3 select-none">
<div class="text-xs font-semibold text-text-primary">Language</div>
<ClockifySelect value="English" class="mt-1.5 w-64 max-w-full">
<template #icon>
<GlobeAltIcon class="h-3.5 w-3.5 flex-none text-text-secondary" />
</template>
</ClockifySelect>
<div class="my-2.5 border-t border-card-border"></div>
<div class="grid grid-cols-2 gap-3">
<div class="min-w-0">
<div class="text-[11px] text-text-secondary">Date format</div>
<ClockifySelect value="MM/DD/YYYY" class="mt-1" />
</div>
<div class="min-w-0">
<div class="text-[11px] text-text-secondary">Time format</div>
<ClockifySelect value="12-hour" class="mt-1" />
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,67 @@
<script setup lang="ts">
// Columns of the "Project export settings" in Clockify, in the order of the two columns there
const columns = [
'Name',
'Client',
'Status',
'Visibility',
'Tasks',
'Tracked (h)',
'Estimated (h)',
'Remaining (h)',
'Overage (h)',
'Progress (%)',
'Project members',
'Project manager',
'Note',
];
</script>
<template>
<div
role="img"
aria-label="Project export settings in Clockify with all columns selected"
class="w-full max-w-md rounded-lg border border-card-border bg-card-background px-4 py-3 select-none">
<div class="text-xs font-semibold text-text-primary">Project export settings</div>
<div class="my-2 border-t border-card-border"></div>
<div class="flex items-center gap-1.5 text-xs text-text-primary">
<span
class="flex h-3.5 w-3.5 flex-none items-center justify-center rounded-[2px] bg-[#03A9F4]">
<svg viewBox="0 0 16 16" fill="none" class="h-3.5 w-3.5 text-white">
<path
d="M4.2 8.4 6.8 11l5-6"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round" />
</svg>
</span>
Select all
</div>
<div class="mt-1.5 grid grid-flow-col grid-rows-7 gap-x-4 gap-y-1">
<div
v-for="column in columns"
:key="column"
class="flex items-center gap-1.5 text-xs text-text-primary">
<span
class="flex h-3.5 w-3.5 flex-none items-center justify-center rounded-[2px] bg-[#03A9F4]">
<svg viewBox="0 0 16 16" fill="none" class="h-3.5 w-3.5 text-white">
<path
d="M4.2 8.4 6.8 11l5-6"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round" />
</svg>
</span>
<span class="truncate">{{ column }}</span>
</div>
</div>
<div class="mt-3 flex justify-end">
<div
class="flex h-7 items-center rounded-sm bg-[#03A9F4] px-4 text-xs font-medium uppercase text-white">
Save
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,60 @@
<script setup lang="ts">
// Projects table in Clockify with the Export menu open
const columns = ['Name', 'Client', 'Tracked'];
const menuItems = ['Save as CSV', 'Save as Excel', 'Customize...'];
</script>
<template>
<div
role="img"
aria-label="Projects table in Clockify with the Export menu at its top right opened"
class="relative w-full max-w-md select-none">
<div class="overflow-hidden border border-card-border bg-card-background">
<div
class="flex h-8 items-center justify-between border-b border-card-border bg-card-background-active">
<span class="px-3 text-[11px] text-text-secondary">Projects</span>
<span
class="flex h-full items-center gap-1 border-l border-card-border px-3 text-[11px] text-text-primary">
Export
<svg viewBox="0 0 8 5" class="h-1 w-1.5 fill-text-secondary">
<path d="M0 0h8L4 5z" />
</svg>
</span>
</div>
<div
class="flex h-7 items-center gap-3 border-b border-card-border px-3 text-[10px] uppercase tracking-wider text-text-secondary">
<span class="h-3 w-3 flex-none rounded-[2px] border border-input-border"></span>
<span
v-for="column in columns"
:key="column"
class="flex flex-1 items-center gap-1">
{{ column }}
<svg viewBox="0 0 8 11" class="h-2 w-1.5 fill-text-tertiary">
<path d="M0 4.5h8L4 0zM0 6.5h8L4 11z" />
</svg>
</span>
</div>
<div class="flex h-8 items-center gap-3 px-3 text-xs text-text-primary">
<span class="h-3 w-3 flex-none rounded-[2px] border border-input-border"></span>
<span class="flex flex-1 items-center gap-1.5">
<span class="h-1 w-1 rounded-full bg-[#A5489B]"></span>
Website
</span>
<span class="flex-1 text-text-secondary">–</span>
<span class="flex-1 text-text-secondary">–</span>
</div>
</div>
<div
class="absolute right-px top-8 w-28 bg-card-background py-0.5 shadow-lg ring-1 ring-card-border">
<div
v-for="item in menuItems"
:key="item"
:class="[
'px-3 py-1 text-xs text-text-primary',
item === 'Customize...' && 'bg-card-background-active',
]">
{{ item }}
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,17 @@
<script setup lang="ts">
// Select of the Clockify preferences with its triangle caret, only used in the previews
defineProps<{
value: string;
}>();
</script>
<template>
<div
class="flex h-7 min-w-0 items-center gap-1.5 rounded border border-input-border bg-input-background px-2 text-xs text-text-primary">
<slot name="icon" />
<span class="flex-1 truncate">{{ value }}</span>
<svg viewBox="0 0 10 5" class="h-1.5 w-2.5 flex-none fill-text-secondary">
<path d="M0 0h10L5 5z" />
</svg>
</div>
</template>

View File

@@ -0,0 +1,22 @@
<script setup lang="ts">
import { computed } from 'vue';
import { getUserTimezone } from '@/packages/ui/src/utils/settings';
import ClockifySelect from './ClockifySelect.vue';
import { timezoneOffset } from './timezoneOffset';
const timezone = getUserTimezone();
// Clockify lists timezones as "(UTC +01:00) Europe/Vienna"
const label = computed(() => `(UTC ${timezoneOffset(timezone)}) ${timezone}`);
</script>
<template>
<div
role="img"
:aria-label="`Time zone in the Clockify preferences set to ${label}`"
class="w-full max-w-md rounded-lg border border-card-border bg-card-background px-4 py-3 select-none">
<div class="text-xs font-semibold text-text-primary">Time settings</div>
<div class="mt-1.5 text-[11px] text-text-secondary">Time zone</div>
<ClockifySelect :value="label" class="mt-1 w-64 max-w-full" />
</div>
</template>

View File

@@ -0,0 +1,58 @@
<script setup lang="ts">
// Clients page in Harvest with the Import/Export menu open
const menuGroups = [
['Import clients from CSV', 'Import contacts from CSV'],
['Export clients', 'Export contacts'],
];
</script>
<template>
<div
role="img"
aria-label="Clients page in Harvest with the Import/Export menu at the top right opened"
class="relative w-full max-w-md select-none rounded-lg border border-card-border bg-card-background">
<div class="flex items-center gap-1.5 border-b border-card-border px-3 py-2.5">
<span class="flex-1 text-sm font-medium text-text-primary">Clients</span>
<span
class="flex h-6 items-center whitespace-nowrap rounded-md bg-[#188433] px-2 text-[11px] font-medium text-white">
+ New client
</span>
<span
class="flex h-6 items-center whitespace-nowrap gap-1 rounded-md border border-card-border px-2 text-[11px] text-text-primary">
Import/Export
<svg viewBox="0 0 10 6" class="h-1.5 w-2.5 stroke-text-secondary" fill="none">
<path d="M1 1l4 4 4-4" stroke-width="1.5" />
</svg>
</span>
</div>
<div class="space-y-1.5 px-3 py-3">
<div
v-for="client in ['Acme Inc.', 'Example Client', 'Globex']"
:key="client"
class="flex items-center gap-2 rounded-md border border-card-border px-2 py-1.5">
<span
class="rounded border border-card-border px-1.5 text-[10px] text-text-secondary"
>Edit</span
>
<span class="text-xs font-medium text-text-primary">{{ client }}</span>
</div>
</div>
<div
class="absolute right-2 top-10 w-44 rounded-md border border-card-border bg-card-background py-1 shadow-lg">
<template v-for="(group, index) in menuGroups" :key="index">
<div v-if="index > 0" class="my-1 border-t border-card-border"></div>
<div
v-for="item in group"
:key="item"
:class="[
'whitespace-nowrap px-3 py-1 text-[11px]',
item === 'Export clients'
? 'bg-text-primary text-card-background'
: 'text-text-primary',
]">
{{ item }}
</div>
</template>
</div>
</div>
</template>

View File

@@ -0,0 +1,57 @@
<script setup lang="ts">
// "Export projects" dialog of Harvest with the active projects and CSV selected
const selection = ['Active', 'Budgeted', 'Archived'];
const formats = ['CSV', 'Excel'];
const optionClass = (selected: boolean) => [
'flex h-6 flex-1 items-center justify-center rounded-md border text-[11px]',
selected
? 'border-[#FA5D00] bg-[#FA5D00]/15 text-text-primary'
: 'border-card-border text-text-primary',
];
</script>
<template>
<div
role="img"
aria-label="Export projects dialog in Harvest with the active projects and the CSV format selected"
class="w-full max-w-md select-none overflow-hidden rounded-lg border border-card-border bg-card-background">
<div
class="border-b border-card-border bg-card-background-active py-1.5 text-center text-xs font-medium text-text-primary">
Export projects
</div>
<div class="space-y-2.5 px-4 py-3">
<div class="space-y-1">
<div class="text-[11px] font-medium text-text-primary">
Which projects would you like to export?
</div>
<div class="flex gap-1.5">
<span
v-for="item in selection"
:key="item"
:class="optionClass(item === 'Active')">
{{ item }}
</span>
</div>
</div>
<div class="space-y-1">
<div class="text-[11px] font-medium text-text-primary">Choose a format:</div>
<div class="flex gap-1.5">
<span v-for="item in formats" :key="item" :class="optionClass(item === 'CSV')">
{{ item }}
</span>
</div>
</div>
<div class="flex gap-1.5">
<span
class="flex h-6 items-center whitespace-nowrap rounded-md bg-[#188433] px-2.5 text-[11px] font-medium text-white">
Export projects
</span>
<span
class="flex h-6 items-center whitespace-nowrap rounded-md border border-card-border px-2.5 text-[11px] text-text-primary">
Cancel
</span>
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,55 @@
<script setup lang="ts">
// Projects page in Harvest with the Export button at the top right
const projects = [
{ client: 'Acme Inc.', name: 'Website' },
{ client: 'Example Client', name: 'Mobile App' },
];
</script>
<template>
<div
role="img"
aria-label="Projects page in Harvest with the Export button at the top right"
class="w-full max-w-md select-none rounded-lg border border-card-border bg-card-background">
<div class="flex items-center gap-1.5 border-b border-card-border px-3 py-2.5">
<span class="flex-1 text-sm font-medium text-text-primary">Projects</span>
<span
class="flex h-6 items-center whitespace-nowrap rounded-md bg-[#188433] px-2 text-[11px] font-medium text-white">
+ New project
</span>
<span
class="flex h-6 items-center whitespace-nowrap rounded-md border border-card-border px-2 text-[11px] text-text-primary">
Import
</span>
<span
class="flex h-6 items-center whitespace-nowrap rounded-md border border-text-secondary px-2 text-[11px] font-medium text-text-primary">
Export
</span>
</div>
<div class="px-3 py-3">
<div class="overflow-hidden rounded-md border border-card-border">
<div
class="flex items-center gap-2 border-b border-card-border bg-card-background-active px-2 py-1 text-[10px] text-text-secondary">
<span class="h-2.5 w-2.5 rounded-[2px] border border-text-quaternary"></span>
<span class="flex-1">Client</span>
<span class="w-12 text-right">Spent</span>
</div>
<template v-for="project in projects" :key="project.name">
<div
class="border-b border-card-border bg-card-background-active px-2 py-0.5 pl-6 text-[10px] text-text-secondary underline">
{{ project.client }}
</div>
<div
class="flex items-center gap-2 border-b border-card-border px-2 py-1.5 last:border-b-0">
<span
class="h-2.5 w-2.5 rounded-[2px] border border-text-quaternary"></span>
<span class="flex-1 text-xs font-medium text-text-primary">
{{ project.name }}
</span>
<span class="w-12 text-right text-xs text-text-primary">0,00</span>
</div>
</template>
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,46 @@
<script setup lang="ts">
// Import/Export settings of Harvest with the "Export all time" button
const navigation = ['Billing', 'Company preferences', 'Modules', 'Import/Export', 'Bulk actions'];
</script>
<template>
<div
role="img"
aria-label="Import/Export settings in Harvest with the Export all time button"
class="w-full max-w-md select-none overflow-hidden rounded-lg border border-card-border bg-card-background">
<div class="border-b border-card-border px-3 py-2 text-sm font-medium text-text-primary">
Settings
</div>
<div class="flex">
<div class="w-32 flex-none space-y-0.5 border-r border-card-border p-2">
<div
v-for="item in navigation"
:key="item"
:class="[
'whitespace-nowrap rounded-md px-2 py-1 text-[11px]',
item === 'Import/Export'
? 'bg-[#FA5D00]/10 font-medium text-text-primary'
: 'text-text-secondary',
]">
{{ item }}
</div>
</div>
<div class="min-w-0 flex-1 space-y-1.5 px-3 py-3">
<div class="text-sm font-semibold text-text-primary">Export data</div>
<div class="text-[10px] leading-snug text-text-secondary">
Export all time and expense data from your Harvest account.
</div>
<div class="flex flex-wrap gap-1.5 pt-1">
<span
class="flex h-6 items-center whitespace-nowrap rounded-md border border-text-secondary px-2 text-[11px] font-medium text-text-primary">
Export all time
</span>
<span
class="flex h-6 items-center whitespace-nowrap rounded-md border border-card-border px-2 text-[11px] text-text-primary">
Export all expenses
</span>
</div>
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,36 @@
<script setup lang="ts">
import { computed } from 'vue';
import type { ImportListItem } from './importSources';
import ImportLinkButton from './ImportLinkButton.vue';
import ImportText from './ImportText.vue';
const props = defineProps<{
items: (string | ImportListItem)[];
}>();
const normalizedItems = computed<ImportListItem[]>(() =>
props.items.map((item) => (typeof item === 'string' ? { text: item } : item))
);
// Lists with previews get more room between the items
const hasPreviews = computed(() => normalizedItems.value.some((item) => item.preview));
</script>
<template>
<ol :class="hasPreviews ? 'space-y-5' : 'space-y-2'">
<li v-for="(item, index) in normalizedItems" :key="item.text" class="flex gap-2.5">
<span
class="flex-none h-5 w-5 rounded-full border border-card-border bg-card-background-active text-xs font-semibold text-text-primary flex items-center justify-center"
>{{ index + 1 }}</span
>
<div class="min-w-0 flex-1 space-y-2">
<p class="max-w-md text-text-primary">
<ImportText :text="item.text" />
</p>
<div v-if="item.preview" class="max-w-md">
<component :is="item.preview" />
</div>
<ImportLinkButton v-if="item.link" v-bind="item.link" />
</div>
</li>
</ol>
</template>

View File

@@ -0,0 +1,16 @@
<script setup lang="ts">
import { ArrowTopRightOnSquareIcon } from '@heroicons/vue/16/solid';
import { Button } from '@/packages/ui/src/Buttons';
defineProps<{
href: string;
label: string;
}>();
</script>
<template>
<Button as="a" variant="ghost" size="sm" :href="href" target="_blank" rel="noopener">
{{ label }}
<ArrowTopRightOnSquareIcon class="text-text-tertiary" />
</Button>
</template>

View File

@@ -0,0 +1,85 @@
<script setup lang="ts">
import { DocumentTextIcon, PuzzlePieceIcon } from '@heroicons/vue/24/outline';
import type { ImportSourceId } from './importSources';
withDefaults(
defineProps<{
source: ImportSourceId;
size?: 'small' | 'base';
}>(),
{
size: 'base',
}
);
</script>
<template>
<span
aria-hidden="true"
:class="[
'flex-none inline-flex items-center justify-center overflow-hidden',
size === 'small' ? 'h-6 w-6 rounded-md' : 'h-9 w-9 rounded-lg',
]">
<!-- Toggl Track mark (Simple Icons, CC0) -->
<svg
v-if="source === 'toggl'"
viewBox="0 0 40 40"
class="h-full w-full"
xmlns="http://www.w3.org/2000/svg">
<rect width="40" height="40" fill="#2C1338" />
<path
transform="translate(8 8)"
fill="#E57CD8"
d="M12 0a12 12 0 1 0 0 24 12 12 0 0 0 0-24zm-.883 4.322h1.766v8.757h-1.766zm-.74 2.053v1.789a4.448 4.448 0 1 0 3.247 0V6.375a6.146 6.146 0 1 1-5.669 10.552 6.145 6.145 0 0 1 2.421-10.552z" />
</svg>
<!-- Clockify mark (Simple Icons, CC0) -->
<svg
v-else-if="source === 'clockify'"
viewBox="0 0 40 40"
class="h-full w-full"
xmlns="http://www.w3.org/2000/svg">
<rect width="40" height="40" fill="#FFFFFF" />
<path
transform="translate(8 8)"
fill="#03A9F4"
d="M13.3512 20.4035c1.1108 0 2.169-.2217 3.139-.6157l2.6913 2.6944C17.4555 23.4458 15.4688 24 13.3512 24 6.729 24 1.3594 18.627 1.3594 12.0006 1.3594 5.3729 6.7289 0 13.3512 0c2.0964 0 4.0652.5406 5.7789 1.4865L16.4834 4.136c-.9687-.3918-2.0236-.6134-3.1322-.6134-4.6379 0-8.3976 3.779-8.3976 8.441 0 4.6609 3.7597 8.4399 8.3976 8.4399zm2.176-12.1544l5.5104-5.5139 1.5773 1.5772-5.5104 5.514zm-2.2328 5.6348c-1.0784 0-1.952-.8775-1.952-1.961 0-1.0825.8736-1.9611 1.952-1.9611 1.0784 0 1.952.8786 1.952 1.961 0 1.0836-.8736 1.9611-1.952 1.9611zm9.3462 5.6953l-1.5772 1.5783-5.5105-5.514 1.5774-1.5783z" />
</svg>
<!-- Harvest mark -->
<svg
v-else-if="source === 'harvest'"
viewBox="0 0 70 70"
class="h-full w-full"
xmlns="http://www.w3.org/2000/svg">
<rect width="70" height="70" fill="#FA5D00" />
<path
fill="#FFFFFF"
d="M55.6916 55.7791C55.6916 57.2818 54.4734 58.5 52.9707 58.5H49.353C47.8503 58.5 46.6321 57.2818 46.6321 55.7791V14.2209C46.6321 12.7182 47.8503 11.5 49.353 11.5H52.9707C54.4734 11.5 55.6916 12.7182 55.6916 14.2209L55.6916 55.7791Z" />
<path
fill="#FFFFFF"
d="M39.5008 27.4713C39.5008 29.4833 38.122 31.2332 36.1658 31.7039L30.4542 33.0781V17.8389C30.4542 16.3362 31.6724 15.118 33.1751 15.118H36.78C38.2827 15.118 39.5008 16.3362 39.5008 17.8389V27.4713Z" />
<path
fill="#FFFFFF"
d="M23.3553 47.3555C23.3552 48.8581 22.1371 50.0761 20.6345 50.0761H17.0296C15.5268 50.0761 14.3086 48.8578 14.3087 47.355L14.3108 25.2504C14.311 23.7478 15.5291 22.5298 17.0317 22.5298H20.6366C22.1394 22.5298 23.3576 23.7481 23.3574 25.2509L23.3553 47.3555Z" />
<path
fill="#FFFFFF"
d="M39.5037 53.165C39.5041 54.668 38.2859 55.8867 36.7829 55.8867H33.1779C31.6755 55.8867 30.4575 54.669 30.457 53.1667L30.4537 42.7934C30.4531 40.7809 31.832 39.0302 33.7887 38.5594L39.4993 37.1854L39.5037 53.165Z" />
</svg>
<!-- solidtime mark -->
<span
v-else-if="source === 'solidtime'"
class="h-full w-full bg-card-background-active text-text-primary flex items-center justify-center">
<svg viewBox="0 0 700 700" class="h-3/4 w-3/4" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(0 700) scale(0.1 -0.1)" fill="currentColor">
<path
d="M3578 5835c-1-1-61-5-133-9-135-7-196-12-255-22-19-3-51-8-70-10-19-3-51-9-70-14-19-5-53-12-74-16-47-7-203-59-296-99-444-188-719-448-855-811-25-67-63-233-70-309-6-56-6-315-1-345 2-14 7-50 11-80 22-176 93-359 192-498 213-299 588-491 1338-687 215-56 395-129 462-188 41-36 73-95 75-140 5-87-32-146-117-186-114-53-385-60-627-15-97 17-262 72-367 121-117 54-362 216-389 257-4 6-21 24-38 39l-32 29-225-229c-124-125-318-322-431-438l-205-210 57-55c292-278 615-463 1078-618 111-38 254-78 314-88 14-3 41-9 60-14 34-8 137-26 210-35 180-24 617-24 805 0 712 92 1222 453 1390 981 66 209 78 509 30 785-11 64-51 172-97 264-137 275-327 450-685 629-145 73-485 191-638 222-93 18-347 101-433 140-135 62-187 122-185 217 1 80 73 152 180 183 59 17 295 24 373 10 132-22 331-86 435-138 73-38 202-133 286-212l73-68 434 436c389 391 433 438 421 453-38 47-57 69-85 97-252 253-524 409-929 534-254 79-441 113-710 127-60 4-131 8-157 10-25 2-48 2-50 0z" />
</g>
</svg>
</span>
<span
v-else
class="h-full w-full bg-card-background-active text-text-secondary flex items-center justify-center">
<DocumentTextIcon v-if="source === 'generic'" class="h-1/2 w-1/2" />
<PuzzlePieceIcon v-else class="h-1/2 w-1/2" />
</span>
</span>
</template>

View File

@@ -0,0 +1,13 @@
<script setup lang="ts">
// Text with parts wrapped in ** shown bold
defineProps<{
text: string;
}>();
</script>
<template>
<template v-for="(part, index) in text.split('**')" :key="index"
><strong v-if="index % 2 === 1" class="font-semibold">{{ part }}</strong
><template v-else>{{ part }}</template></template
>
</template>

View File

@@ -0,0 +1,679 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { storeToRefs } from 'pinia';
import {
ArrowUpTrayIcon,
CheckCircleIcon,
ExclamationTriangleIcon,
} from '@heroicons/vue/24/outline';
import PrimaryButton from '@/packages/ui/src/Buttons/PrimaryButton.vue';
import SecondaryButton from '@/packages/ui/src/Buttons/SecondaryButton.vue';
import LoadingSpinner from '@/packages/ui/src/LoadingSpinner.vue';
import DialogModal from '@/packages/ui/src/DialogModal.vue';
import { formatDateTimeLocalized } from '@/packages/ui/src/utils/time';
import { useOrganizationStore } from '@/utils/useOrganization';
import type { Import, ImportReport } from '@/packages/api/src';
import ImportChecklist from './ImportChecklist.vue';
import ImportWizardHeader from './ImportWizardHeader.vue';
import ImportSourceLogo from './ImportSourceLogo.vue';
import {
buildImportSources,
findSourceStepForImporter,
type ImportSource,
type ImportSourceId,
type ImportSourceStep,
} from './importSources';
import { isActiveImport, type ImportsState } from './useImports';
const props = defineProps<{
state: ImportsState;
}>();
const { organization } = storeToRefs(useOrganizationStore());
// Screens of a source: PREPARE, one screen per step (0..n-1) and the summary (n)
const PREPARE = -1;
// The open source, null while the source picker is shown
const sourceId = defineModel<ImportSourceId | null>('source', { default: null });
const screen = ref(PREPARE);
const dragging = ref(false);
const sources = computed(() => buildImportSources(props.state.importers.value));
const source = computed<ImportSource | null>(
() => sources.value.find((item) => item.id === sourceId.value) ?? null
);
const steps = computed(() => source.value?.steps ?? []);
const isSummary = computed(() => source.value !== null && screen.value >= steps.value.length);
const currentStep = computed<ImportSourceStep | null>(() =>
screen.value >= 0 && screen.value < steps.value.length ? steps.value[screen.value]! : null
);
function importsOfStep(step: ImportSourceStep): Import[] {
return props.state.imports.value.filter((item) => item.type === step.importer);
}
function isStepDone(step: ImportSourceStep): boolean {
return importsOfStep(step).some((item) => item.status === 'completed');
}
/**
* The screen a source opens with: the step of a running import, otherwise the first step after the last
* imported step (the summary if all steps are imported), otherwise the preparation screen.
*/
function initialScreen(item: ImportSource): number {
const active = props.state.activeImport.value;
if (active !== null) {
const activeIndex = item.steps.findIndex((step) => step.importer === active.type);
if (activeIndex !== -1) {
return activeIndex;
}
}
let lastDone = -1;
item.steps.forEach((step, index) => {
if (isStepDone(step)) {
lastDone = index;
}
});
if (lastDone !== -1) {
return lastDone + 1;
}
return item.prerequisites.length > 0 ? PREPARE : 0;
}
function openSource(item: ImportSource, atScreen?: number) {
sourceId.value = item.id;
screen.value = atScreen ?? initialScreen(item);
}
function changeSource() {
sourceId.value = null;
}
// Step detection: open the step of a running import when the page is opened
watch(
() => props.state.loaded.value,
(loaded) => {
const active = props.state.activeImport.value;
if (!loaded || active === null || sourceId.value !== null) {
return;
}
const location = findSourceStepForImporter(sources.value, active.type);
if (location !== null) {
openSource(location.source, location.stepIndex);
}
},
{ immediate: true }
);
/**
* Suggests to continue a source whose last import is not the last step, for example the Toggl time entries after
* the Toggl workspace data was imported.
*/
const continueSuggestion = computed(() => {
const latest = props.state.imports.value[0];
if (latest === undefined || latest.status !== 'completed') {
return null;
}
const location = findSourceStepForImporter(sources.value, latest.type);
if (location === null) {
return null;
}
const nextIndex = location.source.steps.findIndex(
(step, index) => index > location.stepIndex && !isStepDone(step)
);
if (nextIndex === -1) {
return null;
}
return {
source: location.source,
stepIndex: nextIndex,
step: location.source.steps[nextIndex]!,
};
});
const activeImport = computed(() => props.state.activeImport.value);
const activeLocation = computed(() =>
activeImport.value ? findSourceStepForImporter(sources.value, activeImport.value.type) : null
);
const activeIsOnScreen = computed(
() =>
activeLocation.value !== null &&
activeLocation.value.source.id === sourceId.value &&
activeLocation.value.stepIndex === screen.value
);
const uploadBlocked = computed(() => activeImport.value !== null || props.state.uploading.value);
const progressSegments = computed(() =>
steps.value.map((step, index) => ({
key: step.importer,
title: step.title,
done: isStepDone(step),
current: index === screen.value,
}))
);
function stepLabel(step: ImportSourceStep): string {
return step.format === 'File' ? step.title : `${step.title} (${step.format})`;
}
function formatDate(value: string | null): string {
if (value === null) {
return '';
}
return formatDateTimeLocalized(
value,
organization.value?.date_format,
organization.value?.time_format
);
}
function formatReport(report: ImportReport | null): string {
if (report === null) {
return 'Imported';
}
const parts: [number, string, string][] = [
[report.time_entries.created, 'time entry', 'time entries'],
[report.projects.created, 'project', 'projects'],
[report.clients.created, 'client', 'clients'],
[report.tasks.created, 'task', 'tasks'],
[report.tags.created, 'tag', 'tags'],
[report.users.created, 'member', 'members'],
];
const created = parts
.filter(([count]) => count > 0)
.map(
([count, singular, plural]) =>
`${count.toLocaleString()} ${count === 1 ? singular : plural}`
);
return created.length > 0 ? `Created ${created.join(', ')}` : 'Nothing new to create';
}
function importDescription(item: Import): string {
switch (item.status) {
case 'pending':
return 'Waiting to start…';
case 'running':
return 'Importing… You can leave this page, the import continues in the background.';
case 'completed':
return formatReport(item.report);
case 'failed':
return `Failed, nothing was imported. ${item.error_message ?? ''}`.trim();
}
return item.status;
}
// Imports that existed when the page was opened. A step only lists imports of this visit and the ones that ran
// during it, so an import that was already running keeps showing its result. Earlier ones are listed in the
// recent imports.
const importIdsBeforeVisit = ref<Set<string> | null>(null);
const importIdsActiveDuringVisit = ref(new Set<string>());
watch(
() => props.state.loaded.value,
(loaded) => {
if (loaded && importIdsBeforeVisit.value === null) {
importIdsBeforeVisit.value = new Set(props.state.imports.value.map((item) => item.id));
}
},
{ immediate: true }
);
watch(
() => props.state.activeImport.value?.id,
(id) => {
if (id !== undefined) {
importIdsActiveDuringVisit.value.add(id);
}
},
{ immediate: true }
);
const currentStepImports = computed(() =>
currentStep.value
? importsOfStep(currentStep.value)
.filter(
(item) =>
isActive(item) ||
importIdsActiveDuringVisit.value.has(item.id) ||
importIdsBeforeVisit.value?.has(item.id) === false
)
.slice(0, 5)
: []
);
const currentStepDone = computed(() => (currentStep.value ? isStepDone(currentStep.value) : false));
const acceptedFiles = computed(() => {
switch (currentStep.value?.format) {
case 'ZIP':
return '.zip,application/zip';
case 'CSV':
return '.csv,text/csv';
}
return undefined;
});
const uploadTitle = computed(() => {
if (props.state.uploading.value) {
return 'Uploading…';
}
if (activeImport.value !== null) {
return 'Another import is running';
}
const step = currentStep.value;
if (step === null) {
return '';
}
if (currentStepDone.value) {
return step.repeat ? 'Add the next file' : 'Import another file';
}
return step.format === 'File' ? 'Choose the file' : `Choose the ${step.format} file`;
});
const uploadHint = computed(() => {
if (activeImport.value !== null && !props.state.uploading.value) {
return activeIsOnScreen.value
? 'The next file can be added when this import has finished.'
: 'Files can be added when it has finished. You can still go through the other steps.';
}
return 'Drop it here or click to choose. It is imported right away.';
});
async function importFile(file: File | undefined) {
const step = currentStep.value;
if (file === undefined || step === null || uploadBlocked.value) {
return;
}
await props.state.startImport(step.importer, file);
}
function onFileSelected(event: Event) {
const input = event.target as HTMLInputElement;
void importFile(input.files?.[0]);
input.value = '';
}
function onDragLeave(event: DragEvent) {
const currentTarget = event.currentTarget as HTMLElement | null;
if (currentTarget && currentTarget.contains(event.relatedTarget as Node | null)) {
return;
}
dragging.value = false;
}
function onDrop(event: DragEvent) {
dragging.value = false;
void importFile(event.dataTransfer?.files?.[0]);
}
function goBack() {
const firstScreen = source.value?.prerequisites.length ? PREPARE : 0;
if (screen.value <= firstScreen) {
changeSource();
return;
}
screen.value = Math.min(screen.value, steps.value.length) - 1;
}
// Skipping a step without importing a file is confirmed first, since the data of that step will be missing
const showSkipConfirmation = ref(false);
const skipNeedsConfirmation = computed(() => {
const step = currentStep.value;
if (step === null || currentStepDone.value) {
return false;
}
return !importsOfStep(step).some((item) => isActive(item));
});
function goNext() {
if (isSummary.value) {
changeSource();
return;
}
if (skipNeedsConfirmation.value) {
showSkipConfirmation.value = true;
return;
}
screen.value += 1;
}
function confirmSkip() {
showSkipConfirmation.value = false;
screen.value += 1;
}
const isLastStep = computed(() => screen.value === steps.value.length - 1);
const nextLabel = computed(() => {
if (isSummary.value) {
return 'Import from another tool';
}
if (screen.value === PREPARE) {
return 'Continue';
}
if (currentStepDone.value) {
return isLastStep.value ? 'Finish' : 'Next';
}
return isLastStep.value ? 'Skip and finish' : 'Skip';
});
const summaryRows = computed(() =>
steps.value.map((step) => ({
step,
imports: importsOfStep(step).filter((item) => item.status === 'completed'),
}))
);
const summaryHasImports = computed(() => summaryRows.value.some((row) => row.imports.length > 0));
const summaryCreatedMembers = computed(() =>
summaryRows.value.some((row) =>
row.imports.some((item) => (item.report?.users.created ?? 0) > 0)
)
);
function showActiveImport() {
if (activeLocation.value !== null) {
openSource(activeLocation.value.source, activeLocation.value.stepIndex);
}
}
function isActive(item: Import): boolean {
return isActiveImport(item);
}
</script>
<template>
<div class="flex flex-col" data-testid="import_wizard">
<!-- Header of the selected source -->
<ImportWizardHeader
v-if="source"
:source="source"
:segments="progressSegments"
:screen="screen"
@change-source="changeSource" />
<!-- Running import that belongs to another step or source -->
<div
v-if="activeImport && !activeIsOnScreen"
data-testid="import_in_progress"
class="px-4 sm:px-5 py-2.5 text-sm flex items-center gap-3 border-b border-card-background-separator">
<LoadingSpinner class="h-4 w-4 m-0" />
<p class="flex-1 text-text-secondary">
<template v-if="activeLocation">
{{ activeLocation.source.name }}
{{ activeLocation.source.steps[activeLocation.stepIndex]?.title.toLowerCase() }}
{{
activeImport.status === 'running'
? 'are being imported'
: 'are waiting to be imported'
}}.
</template>
<template v-else>An import is running.</template>
</p>
<button
v-if="activeLocation"
type="button"
class="text-sm text-text-primary hover:underline"
@click="showActiveImport">
Show
</button>
</div>
<div class="px-4 sm:px-5 py-5 space-y-4 text-sm">
<div
v-if="state.loadFailed.value"
data-testid="import_load_failed"
class="flex flex-col items-center gap-3 py-10 text-center">
<p class="text-text-secondary">The imports could not be loaded.</p>
<SecondaryButton @click="state.load()">Try again</SecondaryButton>
</div>
<div v-else-if="!state.loaded.value" class="flex justify-center py-10">
<LoadingSpinner />
</div>
<!-- Source picker -->
<template v-else-if="!source">
<div class="space-y-1">
<h3 class="text-base font-semibold text-text-primary">
Where is your data now?
</h3>
<p class="text-text-secondary">
Pick the tool. We show you what to export there and in which order to import
the files.
</p>
</div>
<button
v-if="continueSuggestion"
type="button"
data-testid="import_continue_suggestion"
class="w-full flex items-center gap-3 rounded-lg border border-card-border bg-card-background-active px-3 py-2.5 text-left hover:border-card-border-active"
@click="openSource(continueSuggestion.source, continueSuggestion.stepIndex)">
<ImportSourceLogo :source="continueSuggestion.source.id" size="small" />
<span class="flex-1 min-w-0">
<span class="block font-medium text-text-primary">
Continue with {{ continueSuggestion.source.name }}
</span>
<span class="block text-xs text-text-secondary">
Next: {{ stepLabel(continueSuggestion.step) }}
</span>
</span>
<span class="text-text-secondary" aria-hidden="true">→</span>
</button>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2.5">
<button
v-for="item in sources"
:key="item.id"
type="button"
:data-testid="`import_source_${item.id}`"
class="flex items-center gap-3 rounded-lg border border-card-border bg-card-background px-3 py-2.5 text-left hover:border-card-border-active hover:bg-card-background-active transition"
@click="openSource(item)">
<ImportSourceLogo :source="item.id" />
<span class="min-w-0">
<span class="block font-semibold text-text-primary">{{
item.name
}}</span>
<span class="block text-xs text-text-secondary">{{ item.blurb }}</span>
</span>
</button>
</div>
<p class="text-xs text-text-tertiary">
Using another tool? Export a CSV and use Generic CSV.
</p>
</template>
<!-- Preparation -->
<template v-else-if="screen === PREPARE">
<h3 class="text-base font-semibold text-text-primary">
Before you export from {{ source.name }}
</h3>
<ImportChecklist :items="source.prerequisites" />
</template>
<!-- Step -->
<template v-else-if="currentStep">
<div class="space-y-1">
<div class="text-xs font-medium text-accent-300">
File {{ screen + 1 }} of {{ steps.length }}
<template v-if="currentStep.format !== 'File'">
· {{ currentStep.format }}</template
>
</div>
<h3 class="text-base font-semibold text-text-primary">
<template v-if="currentStep.format === 'File'">{{
currentStep.title
}}</template>
<template v-else>Export the {{ currentStep.title.toLowerCase() }}</template>
</h3>
<p v-if="currentStep.note" class="max-w-md text-text-secondary">
{{ currentStep.note }}
</p>
</div>
<ImportChecklist
v-if="currentStep.instructions.length > 0"
:items="currentStep.instructions" />
<label
:class="[
'flex max-w-md flex-col items-center justify-center gap-1.5 rounded-lg border border-dashed px-4 text-center transition',
currentStepImports.length > 0 ? 'py-5' : 'py-8',
// Below the instructions it is indented like their previews
currentStep.instructions.length > 0 && 'ml-[1.875rem]',
uploadBlocked
? 'border-card-border bg-card-background cursor-not-allowed opacity-70'
: dragging
? 'border-accent-400 bg-card-background-active cursor-pointer'
: 'border-border-secondary bg-card-background-active hover:border-text-quaternary cursor-pointer',
]"
@dragover.prevent="dragging = !uploadBlocked"
@dragleave="onDragLeave"
@drop.prevent="onDrop">
<span
class="mb-1 flex h-10 w-10 items-center justify-center rounded-full bg-card-background text-text-secondary">
<LoadingSpinner v-if="state.uploading.value" class="h-5 w-5 m-0" />
<ArrowUpTrayIcon v-else class="h-5 w-5" />
</span>
<span class="text-base font-semibold text-text-primary">{{ uploadTitle }}</span>
<span class="text-xs text-text-secondary">{{ uploadHint }}</span>
<input
type="file"
class="sr-only"
data-testid="import_file_input"
:accept="acceptedFiles"
:disabled="uploadBlocked"
@change="onFileSelected" />
</label>
<ul
v-if="currentStepImports.length > 0"
:class="[
'max-w-md space-y-1.5',
currentStep.instructions.length > 0 && 'ml-[1.875rem]',
]"
data-testid="import_step_imports">
<li
v-for="item in currentStepImports"
:key="item.id"
:class="[
'flex items-start gap-2.5 rounded-lg border px-3 py-2',
item.status === 'failed'
? 'border-yellow-600/40 bg-yellow-500/5'
: 'border-card-border bg-card-background dark:bg-card-background-active',
]">
<LoadingSpinner v-if="isActive(item)" class="h-4 w-4 m-0 mt-0.5" />
<CheckCircleIcon
v-else-if="item.status === 'completed'"
class="h-4 w-4 flex-none mt-0.5 text-green-500" />
<ExclamationTriangleIcon
v-else
class="h-4 w-4 flex-none mt-0.5 text-yellow-500" />
<span class="flex-1 min-w-0">
<span class="block text-xs text-text-tertiary">{{
formatDate(item.created_at)
}}</span>
<span class="block text-text-primary">{{
importDescription(item)
}}</span>
</span>
</li>
</ul>
</template>
<!-- Summary -->
<template v-else-if="isSummary">
<div class="space-y-1">
<h3 class="text-base font-semibold text-text-primary">
<template v-if="summaryHasImports"
>Import from {{ source.name }} done</template
>
<template v-else>Nothing imported from {{ source.name }} yet</template>
</h3>
<p class="text-text-secondary">
<template v-if="summaryHasImports"
>This is what was imported for each step.</template
>
<template v-else>Go back to a step and add its file to import it.</template>
</p>
</div>
<ul class="space-y-1.5">
<li
v-for="(row, index) in summaryRows"
:key="row.step.importer"
class="flex items-start gap-2.5 rounded-lg border border-card-border bg-card-background dark:bg-card-background-active px-3 py-2">
<CheckCircleIcon
v-if="row.imports.length > 0"
class="h-4 w-4 flex-none mt-0.5 text-green-500" />
<span
v-else
class="h-4 w-4 flex-none mt-0.5 rounded-full border border-border-secondary"></span>
<span class="flex-1 min-w-0">
<span class="block font-medium text-text-primary">{{
stepLabel(row.step)
}}</span>
<span
v-for="item in row.imports"
:key="item.id"
class="block text-text-secondary">
{{ formatReport(item.report) }}
<span class="text-xs text-text-tertiary"
>· {{ formatDate(item.created_at) }}</span
>
</span>
<span v-if="row.imports.length === 0" class="block text-text-secondary">
Not imported.
<button
type="button"
class="underline hover:text-text-primary"
@click="screen = index">
Go to step
</button>
</span>
</span>
</li>
</ul>
<p v-if="summaryCreatedMembers" class="text-text-secondary">
People from the files were added as placeholder members. Invite them from
Members so they can see their time entries.
</p>
</template>
</div>
<div
v-if="source"
class="flex items-center gap-2 px-4 py-3 bg-card-background border-t border-card-background-separator sm:px-5">
<SecondaryButton data-testid="import_wizard_back" @click="goBack">Back</SecondaryButton>
<span class="flex-1"></span>
<PrimaryButton type="button" data-testid="import_wizard_next" @click="goNext">
{{ nextLabel }}
</PrimaryButton>
</div>
<DialogModal
:show="showSkipConfirmation"
max-width="lg"
@close="showSkipConfirmation = false">
<template #title>Skip without importing?</template>
<template #content>
<p v-if="currentStep && source">
You did not import the {{ currentStep.title.toLowerCase() }} from
{{ source.name }} yet.
<template v-if="currentStep.skipWarning">
{{ currentStep.skipWarning }}
</template>
<template v-else>
If you skip this step they will be missing in solidtime.
</template>
<template v-if="isLastStep">You can come back to it later.</template>
<template v-else>
Import it before the next steps, a later import does not update what already
exists in solidtime.
</template>
</p>
</template>
<template #footer>
<SecondaryButton @click="showSkipConfirmation = false">Go back</SecondaryButton>
<PrimaryButton
class="ms-3"
data-testid="import_wizard_skip_confirm"
@click="confirmSkip">
{{ nextLabel }}
</PrimaryButton>
</template>
</DialogModal>
</div>
</template>

View File

@@ -0,0 +1,82 @@
<script setup lang="ts">
import { computed } from 'vue';
import type { ImportSource } from './importSources';
import ImportSourceLogo from './ImportSourceLogo.vue';
export interface ImportProgressSegment {
key: string;
title: string;
done: boolean;
current: boolean;
}
const props = defineProps<{
source: ImportSource;
// Import steps of the source, the preparation is added in front if the source has one
segments: ImportProgressSegment[];
// -1 is the preparation, the number of steps is the summary
screen: number;
}>();
defineEmits<{ changeSource: [] }>();
// Sources without prerequisites open at the first step and have no preparation screen
const hasPreparation = computed(() => props.source.prerequisites.length > 0);
const allSegments = computed<ImportProgressSegment[]>(() => [
...(hasPreparation.value
? [
{
key: 'preparation',
title: 'Preparation',
done: props.screen >= 0,
current: props.screen < 0,
},
]
: []),
...props.segments,
]);
const status = computed(() => {
if (props.screen >= props.segments.length) {
return 'Summary';
}
const stepNumber = props.screen + (hasPreparation.value ? 2 : 1);
return `Step ${stepNumber} of ${allSegments.value.length}`;
});
function dotClass(segment: ImportProgressSegment): string {
if (segment.current) {
return 'w-5 bg-accent-400';
}
return segment.done ? 'w-1.5 bg-accent-400/40' : 'w-1.5 bg-card-background-active';
}
</script>
<template>
<div
class="@container flex items-center gap-2.5 px-4 sm:px-5 py-3.5 border-b border-card-background-separator">
<ImportSourceLogo :source="source.id" size="small" />
<span class="font-semibold text-text-primary truncate">{{ source.name }}</span>
<div class="ml-1 flex flex-none items-center gap-2">
<div class="flex items-center gap-1.5" aria-hidden="true">
<span
v-for="segment in allSegments"
:key="segment.key"
:title="segment.title"
:class="['h-1.5 rounded-full transition-all', dotClass(segment)]"></span>
</div>
<!-- In narrow cards only the dots are shown -->
<span class="hidden @sm:inline text-xs text-text-tertiary whitespace-nowrap">
{{ status }}
</span>
</div>
<span class="flex-1"></span>
<button
type="button"
class="text-sm text-text-secondary hover:text-text-primary whitespace-nowrap"
@click="$emit('changeSource')">
Change source
</button>
</div>
</template>

View File

@@ -0,0 +1,70 @@
<script setup lang="ts">
// Items of the "Data Export" section in the Toggl workspace settings
const items = [
'Projects',
'Project members',
'Project tasks',
'Clients',
'Tags',
'Team',
'Teams',
'Workspace Settings',
'Alerts',
'Custom Reports',
'Scheduled Reports',
'Tracking Reminders',
'Invoices',
];
</script>
<template>
<div
role="img"
aria-label="Data Export in the Toggl workspace settings with all items selected"
class="w-full max-w-md rounded-lg border border-card-border bg-card-background px-4 py-3 select-none">
<div class="text-xs font-semibold text-text-primary">Data Export</div>
<div class="mt-2 flex items-center gap-1.5 text-xs text-text-secondary">
<span
class="flex h-3.5 w-3.5 flex-none items-center justify-center rounded-[3px] bg-[#A5489B] dark:bg-[#BE7CB7]">
<svg
viewBox="0 0 16 16"
fill="none"
class="h-3.5 w-3.5 text-white dark:text-[#1B1B1B]">
<path
d="M4.2 8.4 6.8 11l5-6"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round" />
</svg>
</span>
{{ items.length }} items selected
</div>
<div class="mt-1.5 grid grid-cols-2 gap-x-4 gap-y-1">
<div
v-for="item in items"
:key="item"
class="flex items-center gap-1.5 text-xs text-text-primary">
<span
class="flex h-3.5 w-3.5 flex-none items-center justify-center rounded-[3px] bg-[#A5489B] dark:bg-[#BE7CB7]">
<svg
viewBox="0 0 16 16"
fill="none"
class="h-3.5 w-3.5 text-white dark:text-[#1B1B1B]">
<path
d="M4.2 8.4 6.8 11l5-6"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round" />
</svg>
</span>
<span class="truncate">{{ item }}</span>
</div>
</div>
<div
class="mt-3 flex h-7 w-48 max-w-full items-center justify-center rounded-md bg-[#A5489B] text-xs font-medium text-white dark:bg-[#BE7CB7] dark:text-[#1B1B1B]">
Export to email
</div>
</div>
</template>

View File

@@ -0,0 +1,22 @@
<script setup lang="ts">
const year = new Date().getFullYear();
</script>
<template>
<div
role="img"
:aria-label="`Time entries in the Toggl data export with the year ${year} selected`"
class="w-full max-w-md rounded-lg border border-card-border bg-card-background px-4 py-3 select-none">
<div class="text-xs font-semibold text-text-primary">Time entries</div>
<div class="mt-2.5 flex items-center gap-2">
<div
class="flex h-7 w-32 min-w-0 shrink items-center rounded-md border border-input-border bg-input-background px-2.5 text-xs text-text-primary">
{{ year }}
</div>
<div
class="flex h-7 flex-none items-center whitespace-nowrap rounded-md bg-[#A5489B] px-3 text-xs font-medium text-white dark:bg-[#BE7CB7] dark:text-[#1B1B1B]">
Export time entries
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,29 @@
<script setup lang="ts">
import { computed } from 'vue';
import { ChevronDownIcon } from '@heroicons/vue/20/solid';
import { getUserTimezone } from '@/packages/ui/src/utils/settings';
import { timezoneOffset } from './timezoneOffset';
const timezone = getUserTimezone();
// Toggl lists timezones as "(UTC+01:00) Europe/Vienna"
const label = computed(() => `(UTC${timezoneOffset(timezone)}) ${timezone}`);
</script>
<template>
<div
role="img"
:aria-label="`Account timezone in the Toggl account settings set to ${label}`"
class="w-full max-w-md rounded-lg border border-card-border bg-card-background px-4 py-3 select-none">
<div class="text-xs font-semibold text-text-primary">Time Preferences</div>
<div class="my-2.5 border-t border-card-border"></div>
<div class="text-[10px] font-medium uppercase tracking-wide text-text-tertiary">
Account timezone
</div>
<div
class="mt-1 flex w-64 max-w-full items-center justify-between gap-2 rounded-md border border-input-border bg-input-background px-3 py-1.5 text-xs text-text-primary">
<span class="truncate">{{ label }}</span>
<ChevronDownIcon class="h-3.5 w-3.5 flex-none text-text-secondary" />
</div>
</div>
</template>

View File

@@ -0,0 +1,350 @@
import type { ImportType } from '@/packages/api/src';
import type { Component } from 'vue';
import ClockifyFormatPreview from './ClockifyFormatPreview.vue';
import ClockifyProjectExportPreview from './ClockifyProjectExportPreview.vue';
import ClockifyProjectsTablePreview from './ClockifyProjectsTablePreview.vue';
import ClockifyTimezonePreview from './ClockifyTimezonePreview.vue';
import HarvestClientsExportPreview from './HarvestClientsExportPreview.vue';
import HarvestProjectsExportPreview from './HarvestProjectsExportPreview.vue';
import HarvestProjectsPagePreview from './HarvestProjectsPagePreview.vue';
import HarvestTimeExportPreview from './HarvestTimeExportPreview.vue';
import TogglDataExportPreview from './TogglDataExportPreview.vue';
import TogglTimeEntriesExportPreview from './TogglTimeEntriesExportPreview.vue';
import TogglTimezonePreview from './TogglTimezonePreview.vue';
export type ImportSourceId = 'toggl' | 'clockify' | 'harvest' | 'solidtime' | 'generic' | 'other';
export interface ImportSourceStep {
// Importer key of the backend, see ImporterProvider
importer: string;
title: string;
format: 'ZIP' | 'CSV' | 'File';
// What is missing in solidtime if the step is skipped, replaces the general text of the skip confirmation
skipWarning?: string;
// The source exports one file per year, several files can be imported in this step
repeat?: boolean;
note: string;
instructions: (string | ImportListItem)[];
}
export interface ImportListItem {
// Text wrapped in ** is shown bold
text: string;
link?: { href: string; label: string };
// Recreation of the setting in the source tool, shown below the text
preview?: Component;
}
export interface ImportSource {
id: ImportSourceId;
name: string;
blurb: string;
prerequisites: (string | ImportListItem)[];
steps: ImportSourceStep[];
}
const TOGGL_DATA_EXPORT_LINK = {
href: 'https://track.toggl.com/settings/export',
label: 'Open Toggl data export',
};
const CLOCKIFY_PREFERENCES_LINK = {
href: 'https://app.clockify.me/user/preferences',
label: 'Open Clockify preferences',
};
/**
* Known import sources with their exports in the order they have to be imported.
* Files that contain the organization structure (clients, projects, ...) come before the time entries,
* since they contain details (billable rates, estimates, ...) that the time entry exports do not contain.
*/
const KNOWN_SOURCES: ImportSource[] = [
{
id: 'toggl',
name: 'Toggl Track',
blurb: 'Workspace data, then time entries per year',
prerequisites: [
'Sign in to Toggl as an **Admin of the workspace**. Other members can only export their own time entries.',
{
text: 'Set the **same timezone in Toggl as in solidtime**',
link: {
href: 'https://track.toggl.com/account',
label: 'Open Toggl account settings',
},
preview: TogglTimezonePreview,
},
],
steps: [
{
importer: 'toggl_data_importer',
title: 'Workspace data',
format: 'ZIP',
note: 'Clients, projects, tasks, tags and members. Time entries are exported in the next step.',
instructions: [
{
text: 'In Toggl open Admin, then Settings, then Data export',
link: TOGGL_DATA_EXPORT_LINK,
},
{
text: 'Under "Data export" select all items and click "Export to email"',
preview: TogglDataExportPreview,
},
'Download the ZIP from the email (log in to Toggl first) and add it here',
],
},
{
importer: 'toggl_time_entries',
title: 'Time entries',
format: 'CSV',
repeat: true,
note: 'Toggl exports one file per year. Import every year you want to bring over.',
instructions: [
{
text: 'On the same Data export page find "Time entries"',
link: TOGGL_DATA_EXPORT_LINK,
},
{
text: 'Select a year and click "Export time entries"',
preview: TogglTimeEntriesExportPreview,
},
'Add the file here and repeat for each year',
],
},
],
},
{
id: 'clockify',
name: 'Clockify',
blurb: 'Projects, then time entries per year',
prerequisites: [
{
text: 'Under **General in the Clockify preferences** set the language to **English**, the date format to **MM/DD/YYYY** and the time format to **12-hour**',
link: CLOCKIFY_PREFERENCES_LINK,
preview: ClockifyFormatPreview,
},
{
text: 'Set the **same timezone in Clockify as in solidtime**',
link: CLOCKIFY_PREFERENCES_LINK,
preview: ClockifyTimezonePreview,
},
'Check that your Clockify plan includes **CSV exports** (Basic or higher)',
],
steps: [
{
importer: 'clockify_projects',
title: 'Projects',
format: 'CSV',
note: '',
skipWarning:
'Billable rates, billable status and estimates of the projects are not in the time report and will be missing in solidtime.',
instructions: [
{
text: 'Open Projects in the left navigation, click **Export** at the top right of the projects table, then **Customize...**',
link: {
href: 'https://app.clockify.me/projects',
label: 'Open Clockify projects',
},
preview: ClockifyProjectsTablePreview,
},
{
text: 'Make sure **all columns are selected** and click Save',
preview: ClockifyProjectExportPreview,
},
'Click Export again, then **Save as CSV**, and add the file here',
],
},
{
importer: 'clockify_time_entries',
title: 'Time entries',
format: 'CSV',
repeat: true,
note: 'The detailed report covers at most one year per file. Import one file per year.',
instructions: [
'Open Reports, then Time, then Detailed',
'Pick a date range of up to one year (top right)',
'Click Export, then Save as CSV, and add the file here',
],
},
],
},
{
id: 'harvest',
name: 'Harvest',
blurb: 'Clients, projects, then all time entries',
prerequisites: [
'Sign in to Harvest as an **Administrator**',
'Set the **same timezone in Harvest as in solidtime**',
],
steps: [
{
importer: 'harvest_clients',
title: 'Clients',
format: 'CSV',
note: '',
skipWarning:
'Clients that have no projects or time entries will be missing in solidtime.',
instructions: [
{
text: 'Open Clients in the left navigation, click **Import/Export** at the top right, then **Export clients**',
link: {
href: 'https://harvestapp.com/clients',
label: 'Open Harvest clients',
},
preview: HarvestClientsExportPreview,
},
'Add the downloaded CSV file here',
],
},
{
importer: 'harvest_projects',
title: 'Projects',
format: 'CSV',
note: '',
skipWarning:
'Billable status and estimates of the projects are not in the time entries export and will be missing in solidtime.',
instructions: [
{
text: 'Open Projects in the left navigation and click **Export** at the top right',
link: {
href: 'https://harvestapp.com/projects',
label: 'Open Harvest projects',
},
preview: HarvestProjectsPagePreview,
},
{
text: 'Select **Active**, choose **CSV** and click **Export projects**. Harvest sends the file by email.',
preview: HarvestProjectsExportPreview,
},
'Download the file from the email and add it here',
],
},
{
importer: 'harvest_time_entries',
title: 'Time entries',
format: 'CSV',
note: 'One file with all time entries. Large accounts get it by email.',
instructions: [
{
text: 'Open Settings, then **Import/Export**, and click **Export all time** under "Export data"',
link: {
href: 'https://harvestapp.com/company/settings/import_export',
label: 'Open Harvest import/export settings',
},
preview: HarvestTimeExportPreview,
},
'Add the downloaded CSV file here',
],
},
],
},
{
id: 'solidtime',
name: 'solidtime',
blurb: 'Another instance or organization',
prerequisites: [
'Sign in to the other solidtime as **Admin or Owner** of the organization you export',
],
steps: [
{
importer: 'solidtime',
title: 'Organization data',
format: 'ZIP',
note: 'Everything in one file: members, clients, projects, tasks, tags and time entries.',
instructions: [
'In the other solidtime instance select the organization (top left)',
'Open Import / Export in the navigation',
'Click "Export Organization Data" and add the ZIP here',
],
},
],
},
{
id: 'generic',
name: 'Generic CSV',
blurb: 'Your own spreadsheet',
prerequisites: [
'Save the file **comma separated** and **UTF-8 encoded**',
'Write all times in **UTC as ISO 8601**, for example 2024-03-04T09:23:00Z',
],
steps: [
{
importer: 'generic_projects',
title: 'Projects',
format: 'CSV',
note: 'Columns: name, color, billable_rate (in cents), is_public, client, billable_default, estimated_time (in seconds), archived_at.',
skipWarning:
'Colors, billable rates, visibility, estimates and the archived state of the projects will be missing in solidtime.',
instructions: [
{
text: 'Create a CSV with the columns above, one project per row. The docs describe every column and its format.',
link: {
href: 'https://docs.solidtime.io/user-guide/import#generic-projects-importer',
label: 'Open the docs',
},
},
],
},
{
importer: 'generic_time_entries',
title: 'Time entries',
format: 'CSV',
note: 'Columns: description, billable, client, project, tags, start, end, task, user_name, user_email.',
instructions: [
{
text: 'Create a CSV with the columns above, one time entry per row. The docs describe every column and its format.',
link: {
href: 'https://docs.solidtime.io/user-guide/import#generic-time-entries-importer',
label: 'Open the docs',
},
},
],
},
],
},
];
/**
* Builds the sources for the importers available on this instance. Steps of importers that are not available are
* removed, importers that are not part of a known source (for example from extensions) are grouped in "Other".
*/
export function buildImportSources(importers: ImportType[]): ImportSource[] {
const available = new Set(importers.map((importer) => importer.key));
const sources = KNOWN_SOURCES.map((source) => ({
...source,
steps: source.steps.filter((step) => available.has(step.importer)),
})).filter((source) => source.steps.length > 0);
const knownImporters = new Set(
KNOWN_SOURCES.flatMap((source) => source.steps.map((step) => step.importer))
);
const otherImporters = importers.filter((importer) => !knownImporters.has(importer.key));
if (otherImporters.length > 0) {
sources.push({
id: 'other',
name: 'Other',
blurb: 'More importers',
prerequisites: [],
steps: otherImporters.map((importer) => ({
importer: importer.key,
title: importer.name,
format: 'File',
note: '',
instructions: [],
})),
});
}
return sources;
}
export function findSourceStepForImporter(
sources: ImportSource[],
importer: string
): { source: ImportSource; stepIndex: number } | null {
for (const source of sources) {
const stepIndex = source.steps.findIndex((step) => step.importer === importer);
if (stepIndex !== -1) {
return { source, stepIndex };
}
}
return null;
}

View File

@@ -0,0 +1,12 @@
import { getDayJsInstance } from '@/packages/ui/src/utils/time';
/**
* Current UTC offset of a timezone, for example "+01:00" for Europe/Vienna in winter.
*/
export function timezoneOffset(timezone: string): string {
try {
return getDayJsInstance()().tz(timezone).format('Z');
} catch {
return '+00:00';
}
}

View File

@@ -0,0 +1,170 @@
import { computed, getCurrentInstance, onUnmounted, ref } from 'vue';
import { api } from '@/packages/api/src';
import type { Import, ImportType } from '@/packages/api/src';
import { useNotificationsStore } from '@/utils/notification';
import { initializeStores } from '@/utils/init';
const POLL_INTERVAL_MS = 2000;
export function isActiveImport(item: Import): boolean {
return item.status === 'pending' || item.status === 'running';
}
function toBase64(file: File): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
if (typeof reader.result !== 'string') {
reject(new Error('Could not read the file'));
return;
}
// Strip the "data:<type>;base64," prefix
resolve(reader.result.substring(reader.result.indexOf(',') + 1));
};
reader.onerror = () => reject(reader.error);
reader.readAsDataURL(file);
});
}
/**
* State of the imports of an organization: the available importers, the recent imports and the running import.
* Imports are processed in the background, the running import is polled until it is finished.
*/
export function useImports(organizationId: string) {
const { addNotification, handleApiRequestNotifications } = useNotificationsStore();
const importers = ref<ImportType[]>([]);
const imports = ref<Import[]>([]);
const loaded = ref(false);
const loadFailed = ref(false);
const uploading = ref(false);
const activeImport = computed(() => imports.value.find(isActiveImport) ?? null);
let stopped = false;
let polling = false;
if (getCurrentInstance()) {
onUnmounted(() => {
stopped = true;
});
}
function upsert(updatedImport: Import) {
const index = imports.value.findIndex((item) => item.id === updatedImport.id);
if (index === -1) {
imports.value = [updatedImport, ...imports.value];
} else {
imports.value[index] = updatedImport;
}
}
/**
* Loads the importers and the imports. A failed request is shown as a notification and sets loadFailed,
* so the page can offer to try again instead of loading forever.
*/
async function load() {
loadFailed.value = false;
let responses;
try {
responses = await handleApiRequestNotifications(
() =>
Promise.all([
api.getImporters({ params: { organization: organizationId } }),
api.getImports({ params: { organization: organizationId } }),
]),
undefined,
'Could not load the imports'
);
} catch {
// The error was shown as a notification
loadFailed.value = true;
return;
}
const [importersResponse, importsResponse] = responses;
importers.value = importersResponse.data;
imports.value = importsResponse.data;
loaded.value = true;
void pollActiveImport();
}
async function pollActiveImport() {
if (polling) {
return;
}
polling = true;
try {
while (!stopped && activeImport.value !== null) {
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
const current = activeImport.value;
if (stopped || current === null) {
break;
}
try {
const updated = (
await api.getImport({
params: { organization: organizationId, import: current.id },
})
).data;
upsert(updated);
if (updated.status === 'completed') {
// The import created clients, projects, tags, ... that the stores do not know yet
initializeStores();
}
} catch {
// A failed status check (for example a network issue) is retried with the next poll
}
}
} finally {
polling = false;
}
}
/**
* Uploads the file and starts the import, the import is processed in the background.
*/
async function startImport(importer: string, file: File): Promise<Import | null> {
uploading.value = true;
try {
let data: string;
try {
data = await toBase64(file);
} catch {
addNotification('error', 'Could not read the file');
return null;
}
let response;
try {
response = await handleApiRequestNotifications(() =>
api.importData(
{ type: importer, data: data },
{ params: { organization: organizationId } }
)
);
} catch {
// The error was shown as a notification
return null;
}
upsert(response.data);
if (response.data.status === 'completed') {
initializeStores();
}
void pollActiveImport();
return response.data;
} finally {
uploading.value = false;
}
}
return {
importers,
imports,
loaded,
loadFailed,
uploading,
activeImport,
load,
startImport,
};
}
export type ImportsState = ReturnType<typeof useImports>;

View File

@@ -5,6 +5,11 @@ import { ArrowsRightLeftIcon } from '@heroicons/vue/16/solid';
import PageTitle from '@/Components/Common/PageTitle.vue';
import ImportData from '@/Pages/Teams/Partials/ImportData.vue';
import ExportData from '@/Pages/Teams/Partials/ExportData.vue';
import { onMounted } from 'vue';
import { useOrganizationStore } from '@/utils/useOrganization';
// The organization name and date/time formats are shown in the import and export sections
onMounted(() => useOrganizationStore().fetchOrganization());
</script>
<template>

View File

@@ -7,10 +7,11 @@ import { api, type Export } from '@/packages/api/src';
import { getCurrentOrganizationId } from '@/utils/useUser';
import DialogModal from '@/packages/ui/src/DialogModal.vue';
import SecondaryButton from '@/packages/ui/src/Buttons/SecondaryButton.vue';
import { ArrowUpOnSquareIcon, InformationCircleIcon } from '@heroicons/vue/24/outline';
import { ArrowUpOnSquareIcon } from '@heroicons/vue/24/outline';
import { CardTitle } from '@/packages/ui/src';
import Card from '@/Components/Common/Card.vue';
import { useOrganizationStore } from '@/utils/useOrganization';
import ImportLinkButton from '@/Components/Import/ImportLinkButton.vue';
import { formatDateTimeLocalized } from '@/packages/ui/src/utils/time';
const EXPORT_POLL_INTERVAL_MS = 2000;
@@ -196,21 +197,11 @@ function statusLabel(item: Export): string {
<SecondaryButton @click="showResultModal = false"> Close </SecondaryButton>
</template>
</DialogModal>
<div>
<!-- Same spacing between title and card as the dashboard cards -->
<div class="flex flex-col gap-1.5">
<CardTitle title="Export Data" :icon="ArrowUpOnSquareIcon"></CardTitle>
<Card class="mb-3">
<div class="py-2 px-3 sm:px-4 text-sm flex items-center space-x-3">
<InformationCircleIcon class="h-5 min-w-0 w-5 text-bg-tertiary" />
<p class="flex-1">
Export your solidtime organization data. This will include all clients,
projects, tasks, and time entries. You will receive a zip file with CSV files
for each entity. The export is prepared in the background, you can leave this
page and download it later.
</p>
</div>
</Card>
<Card>
<div class="py-6 flex-col items-center flex space-y-5 text-center text-sm">
<div class="py-6 px-4 flex-col items-center flex space-y-5 text-center text-sm">
<div>
The following organization will be exported: <br />
<strong class="font-semibold">{{ organization?.name }}</strong>
@@ -218,14 +209,23 @@ function statusLabel(item: Export): string {
<PrimaryButton :loading="loading || exportInProgress" @click="exportData"
>Export Organization Data
</PrimaryButton>
<div class="flex flex-col items-center gap-1">
<p class="max-w-md text-text-secondary">
Export your solidtime organization data. This will include all clients,
projects, tasks, and time entries.
</p>
<ImportLinkButton
href="https://docs.solidtime.io/user-guide/export"
label="Read the export docs" />
</div>
<div v-if="exportInProgress" class="text-text-secondary">
The export is being prepared, the download starts automatically when it is
ready.
</div>
</div>
<div
v-if="exports.length > 0"
class="border-t border-card-background-separator px-4 py-3 sm:px-5 text-sm">
</Card>
<Card v-if="exports.length > 0" class="mt-1.5">
<div class="px-4 py-3 sm:px-5 text-sm">
<div class="font-semibold text-text-primary pb-2">Recent exports</div>
<ul>
<li

View File

@@ -1,287 +1,119 @@
<script setup lang="ts">
import PrimaryButton from '@/packages/ui/src/Buttons/PrimaryButton.vue';
import { computed, onMounted, onUnmounted, ref } from 'vue';
import { useNotificationsStore } from '@/utils/notification';
import { api } from '@/packages/api/src';
import { Field, FieldLabel } from '@/packages/ui/src/field';
import { DocumentIcon } from '@heroicons/vue/24/solid';
import {
ArrowDownOnSquareIcon,
ExclamationTriangleIcon,
InformationCircleIcon,
} from '@heroicons/vue/24/outline';
import { computed, onMounted, ref } from 'vue';
import { storeToRefs } from 'pinia';
import { ArrowDownOnSquareIcon, ExclamationTriangleIcon } from '@heroicons/vue/24/outline';
import { canUseBillableRates } from '@/utils/billing';
import { getCurrentOrganizationId } from '@/utils/useUser';
import type { Import, ImportReport, ImportType } from '@/packages/api/src';
import DialogModal from '@/packages/ui/src/DialogModal.vue';
import SecondaryButton from '@/packages/ui/src/Buttons/SecondaryButton.vue';
import { initializeStores } from '@/utils/init';
import type { Import } from '@/packages/api/src';
import { CardTitle } from '@/packages/ui/src';
import Card from '@/Components/Common/Card.vue';
import { formatDateTimeLocalized } from '@/packages/ui/src/utils/time';
import { useOrganizationStore } from '@/utils/useOrganization';
import ImportWizard from '@/Components/Import/ImportWizard.vue';
import { useImports } from '@/Components/Import/useImports';
import type { ImportSourceId } from '@/Components/Import/importSources';
const importTypeOptions = ref<ImportType[]>([]);
const organizationId = getCurrentOrganizationId();
const importsState = useImports(organizationId ?? '');
const { imports, importers } = importsState;
const { addNotification } = useNotificationsStore();
const { organization } = storeToRefs(useOrganizationStore());
const loading = ref(false);
// Recent imports are only shown while no source is open in the wizard
const openSource = ref<ImportSourceId | null>(null);
const billableRatesLocked = computed(() => !canUseBillableRates());
onMounted(async () => {
const organizationId = getCurrentOrganizationId();
if (organizationId) {
importTypeOptions.value = (
await api.getImporters({
params: {
organization: organizationId,
},
})
).data;
}
});
const reportResult = ref<ImportReport | null>();
const files = ref<FileList | null>(null);
async function importData() {
if (importType.value === null) {
addNotification('error', 'Please select the import type');
return;
}
if (files.value?.length !== 1) {
addNotification('error', 'Please select the CSV or ZIP file that you want to import');
return;
}
const rawBase64String = await toBase64(files.value[0]!);
const base64String = rawBase64String.split(';')[1]!.replace('base64,', '') as string;
const organizationId = getCurrentOrganizationId();
if (organizationId !== null) {
const { handleApiRequestNotifications } = useNotificationsStore();
loading.value = true;
try {
const response = await handleApiRequestNotifications(() => {
if (importType.value) {
return api.importData(
{
type: importType.value.key,
data: base64String,
},
{
params: {
organization: organizationId,
},
}
);
}
return new Promise<never>((resolve, reject) => {
reject('Import type is null');
});
});
if (response === undefined) {
return;
}
const finishedImport = await handleApiRequestNotifications(() =>
waitForImport(organizationId, response.data)
);
if (finishedImport === undefined || isUnmounted) {
return;
}
if (finishedImport.status === 'failed') {
addNotification(
'error',
'Import failed',
finishedImport.error_message ?? 'The import failed, no data was imported.'
);
return;
}
initializeStores();
reportResult.value = finishedImport.report;
if (reportResult.value) {
showResultModal.value = true;
}
} finally {
loading.value = false;
}
await importsState.load();
}
}
const IMPORT_POLL_INTERVAL_MS = 2000;
let isUnmounted = false;
onUnmounted(() => {
isUnmounted = true;
});
/**
* The import is processed in the background, poll it until it is completed or failed.
*/
async function waitForImport(organizationId: string, currentImport: Import): Promise<Import> {
while (
(currentImport.status === 'pending' || currentImport.status === 'running') &&
!isUnmounted
) {
await new Promise((resolve) => setTimeout(resolve, IMPORT_POLL_INTERVAL_MS));
currentImport = (
await api.getImport({
params: {
organization: organizationId,
import: currentImport.id,
},
})
).data;
function importTypeName(type: string): string {
return importers.value.find((importer) => importer.key === type)?.name ?? type;
}
function statusLabel(item: Import): string {
switch (item.status) {
case 'pending':
return 'Waiting';
case 'running':
return 'In progress';
case 'completed':
return 'Completed';
case 'failed':
return 'Failed';
}
return currentImport;
return item.status;
}
const importFile = ref<HTMLInputElement | null>();
function toBase64(file: File): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
if (reader.result instanceof ArrayBuffer) {
const decoder = new TextDecoder();
const str = decoder.decode(reader.result);
return reject(str);
} else if (reader.result) {
resolve(reader.result);
}
};
reader.onerror = reject;
});
}
function updateFiles() {
files.value = importFile.value?.files ?? null;
}
const currentImporterDescription = computed(() => {
if (importType.value === null) {
return '';
}
return importType.value.description;
});
const filenames = computed(() => {
return files.value?.item(0)?.name ?? 'Import File selected';
});
const importType = ref<ImportType | null>(null);
const showResultModal = ref(false);
</script>
<template>
<DialogModal closeable :show="showResultModal" @close="showResultModal = false">
<template #title>Import Result</template>
<template #content>
<div class="pb-6">
The import was successful! Here is an overview of the imported data:
</div>
<div class="py-2.5 px-3 border-t border-t-card-background-separator">
<span class="text-text-primary font-semibold">Clients created:</span>
{{ reportResult?.clients.created }}
</div>
<div class="py-2.5 px-3 border-t border-t-card-background-separator">
<span class="text-text-primary font-semibold">Projects created:</span>
{{ reportResult?.projects.created }}
</div>
<div class="py-2.5 px-3 border-t border-t-card-background-separator">
<span class="text-text-primary font-semibold">Tasks created:</span>
{{ reportResult?.tasks.created }}
</div>
<div class="py-2.5 px-3 border-t border-t-card-background-separator">
<span class="text-text-primary font-semibold">Time entries created:</span>
{{ reportResult?.time_entries.created }}
</div>
</template>
<template #footer>
<SecondaryButton @click="showResultModal = false"> Close </SecondaryButton>
</template>
</DialogModal>
<div>
<!-- Same spacing between title and card as the dashboard cards -->
<div class="flex flex-col gap-1.5">
<CardTitle title="Import Data" :icon="ArrowDownOnSquareIcon"></CardTitle>
<Card class="mb-3">
<div class="py-2 px-3 sm:px-4 text-sm flex items-center space-x-3">
<InformationCircleIcon class="h-5 min-w-0 w-5 text-bg-tertiary" />
<p class="flex-1">
Import existing data from Toggl, Clockify, Harvest, generic CSV files or a
different solidtime instance. Please select the type of data you want to import
and follow the instructions.
</p>
</div>
<div
v-if="billableRatesLocked"
class="py-2 px-3 sm:px-4 text-sm flex items-center space-x-3 border-t border-card-background-separator">
<ExclamationTriangleIcon class="h-5 min-w-0 w-5 text-yellow-500" />
<p class="flex-1">
<div v-if="billableRatesLocked" class="mb-1.5 text-sm text-text-secondary">
<p class="flex items-start space-x-2">
<ExclamationTriangleIcon class="h-5 min-w-0 w-5 text-yellow-500 shrink-0" />
<span>
Billable rates and billable status will not be imported, since they are not
available in the free plan. All projects and time entries will be imported as
non-billable.
</p>
</div>
</Card>
</span>
</p>
</div>
<Card>
<div class="px-4 py-5 sm:px-5">
<Field>
<FieldLabel for="importType">Import Type</FieldLabel>
<select
id="importType"
v-model="importType"
name="importType"
class="block w-full border-input-border bg-input-background text-text-primary focus:border-input-border-active rounded-md shadow-sm">
<option :value="null" selected disabled>
Select an import type to get instructions...
</option>
<option
v-for="importTypeOption in importTypeOptions"
:key="importTypeOption.key"
:value="importTypeOption">
{{ importTypeOption.name }}
</option>
</select>
<div v-if="currentImporterDescription" class="py-3 text-text-primary">
<div class="font-semibold text-text-secondary py-1">Instructions:</div>
<div class="max-w-2xl" v-html="currentImporterDescription"></div>
</div>
</Field>
<ImportWizard v-model:source="openSource" :state="importsState" />
</Card>
<div
class="mt-2 flex justify-center rounded-lg border border-dashed border-border-primary px-6 py-10">
<div class="text-center">
<DocumentIcon
class="mx-auto h-8 w-8 text-text-secondary"
aria-hidden="true" />
<div class="mt-4 flex text-sm leading-6 text-text-secondary">
<label
for="file-upload"
class="relative cursor-pointer rounded-md font-semibold text-text-primary focus-within:outline-none focus-within:ring-2 focus-within:ring-indigo-600 focus-within:ring-offset-2 focus-within:ring-offset-gray-900 hover:text-indigo-500">
<span v-if="files">{{ filenames }}</span>
<span v-else>Upload the Export file</span>
<input
id="file-upload"
ref="importFile"
name="file-upload"
type="file"
class="sr-only"
@change="updateFiles" />
</label>
<Card v-if="openSource === null && imports.length > 0" class="mt-1.5">
<div class="px-4 py-3 sm:px-5 text-sm" data-testid="recent_imports">
<div class="font-semibold text-text-primary pb-2">Recent imports</div>
<ul>
<li
v-for="item in imports"
:key="item.id"
class="py-2 border-t first:border-t-0 border-card-background-separator">
<div class="flex items-center justify-between space-x-3">
<div class="text-text-primary">
<span v-if="item.created_at">
{{
formatDateTimeLocalized(
item.created_at,
organization?.date_format,
organization?.time_format
)
}}
</span>
<span class="pl-3">{{ importTypeName(item.type) }}</span>
</div>
<span
:class="[
item.status === 'failed'
? 'text-red-500'
: 'text-text-tertiary',
'whitespace-nowrap',
]"
>{{ statusLabel(item) }}</span
>
</div>
<p class="text-xs leading-5 text-text-secondary">
CSV and ZIP are supported
</p>
</div>
</div>
</div>
<div
class="flex items-center justify-end px-4 py-3 bg-card-background border-t border-card-background-separator text-end sm:px-6 shadow sm:rounded-bl-md sm:rounded-br-md">
<PrimaryButton :loading @click="importData">Import Data </PrimaryButton>
<div
v-if="item.status === 'completed' && item.report"
class="text-text-secondary text-xs pt-1">
{{ item.report.time_entries.created }} time entries,
{{ item.report.projects.created }} projects,
{{ item.report.clients.created }} clients,
{{ item.report.tasks.created }} tasks created
</div>
<div
v-else-if="item.status === 'failed' && item.error_message"
class="text-text-secondary text-xs pt-1">
{{ item.error_message }}
</div>
</li>
</ul>
</div>
</Card>
</div>

View File

@@ -32,7 +32,7 @@ const sizeClasses = {
:disabled="loading"
:class="
twMerge(
'bg-button-secondary-background border border-button-secondary-border hover:bg-button-secondary-background-hover shadow-sm transition text-text-primary rounded-lg font-medium inline-flex items-center space-x-1.5 focus-visible:outline-none focus-visible:border-transparent focus-visible:ring-2 focus-visible:ring-ring focus:border-transparent disabled:opacity-25 ease-in-out',
'bg-button-secondary-background border border-button-secondary-border hover:bg-button-secondary-background-hover shadow-sm transition text-text-primary rounded-lg font-medium inline-flex items-center space-x-1.5 focus-visible:outline-none focus-visible:border-transparent focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-25 ease-in-out',
sizeClasses[props.size],
props.class
)