'use client'; import { useState } from 'react'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { AuthGuard } from '@/components/AuthGuard'; import { DashboardLayout } from '@/components/DashboardLayout'; import { userApi, gmailApi, smtpApi } from '@/lib/api'; import { useAuthStore } from '@/store/authStore'; import { CheckCircle, Loader2, User, Mail, Shield, Server, AlertTriangle, XCircle, Bug, RotateCcw, Tags, Send, } from 'lucide-react'; const DEFAULT_GMAIL_IMPORT_LABEL_TEMPLATES = ['{{source_email}}', 'imported']; function parseImportLabelTemplates(input: string): string[] { return input .split('\n') .map((value) => value.trim()) .filter((value, index, values) => value.length > 0 && values.indexOf(value) === index); } function GmailImportLabelsForm({ gmailCredential, onSave, isSaving, }: { gmailCredential: { gmail_email: string; import_label_templates: string[]; default_import_label_templates: string[]; }; onSave: (labels: string[]) => void; isSaving: boolean; }) { const [labelsInput, setLabelsInput] = useState( gmailCredential.import_label_templates.join('\n') ); const defaultTemplates = gmailCredential.default_import_label_templates.length > 0 ? gmailCredential.default_import_label_templates : DEFAULT_GMAIL_IMPORT_LABEL_TEMPLATES; const parsedLabels = parseImportLabelTemplates(labelsInput); const isDefaultSelection = parsedLabels.length === defaultTemplates.length && parsedLabels.every((value, index) => value === defaultTemplates[index]); return (

Import labels

One label is created per line. We recommend keeping{' '} {'{{source_email}}'} {' '} so each imported message is tagged with the mailbox it came from, plus a catch-all label like imported.

Example: a mail pulled from billing@example.com will be labeled as billing@example.com when{' '} {'{{source_email}}'} {' '} is present.