@fayz-ai/plugin-crm 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CrmContext.d.ts +32 -0
- package/dist/CrmContext.d.ts.map +1 -0
- package/dist/CrmPage.d.ts +13 -0
- package/dist/CrmPage.d.ts.map +1 -0
- package/dist/cascade.d.ts +13 -0
- package/dist/cascade.d.ts.map +1 -0
- package/dist/components/CrmGeneralSettings.d.ts +3 -0
- package/dist/components/CrmGeneralSettings.d.ts.map +1 -0
- package/dist/components/CrmOnboarding.d.ts +5 -0
- package/dist/components/CrmOnboarding.d.ts.map +1 -0
- package/dist/components/PipelineSettings.d.ts +3 -0
- package/dist/components/PipelineSettings.d.ts.map +1 -0
- package/dist/components/QuoteStatusDropdown.d.ts +8 -0
- package/dist/components/QuoteStatusDropdown.d.ts.map +1 -0
- package/dist/data/index.d.ts +3 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/mock.d.ts +9 -0
- package/dist/data/mock.d.ts.map +1 -0
- package/dist/data/supabase.d.ts +9 -0
- package/dist/data/supabase.d.ts.map +1 -0
- package/dist/data/types.d.ts +32 -0
- package/dist/data/types.d.ts.map +1 -0
- package/dist/index.cjs +4601 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4595 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/tenant.d.ts +3 -0
- package/dist/lib/tenant.d.ts.map +1 -0
- package/dist/locales/en.d.ts +2 -0
- package/dist/locales/en.d.ts.map +1 -0
- package/dist/locales/index.d.ts +2 -0
- package/dist/locales/index.d.ts.map +1 -0
- package/dist/locales/pt-BR.d.ts +2 -0
- package/dist/locales/pt-BR.d.ts.map +1 -0
- package/dist/registries.d.ts +3 -0
- package/dist/registries.d.ts.map +1 -0
- package/dist/schema/index.d.ts +1036 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/store.d.ts +43 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/types.d.ts +238 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/views/ActivityListView.d.ts +3 -0
- package/dist/views/ActivityListView.d.ts.map +1 -0
- package/dist/views/DashboardView.d.ts +9 -0
- package/dist/views/DashboardView.d.ts.map +1 -0
- package/dist/views/DealSidebar.d.ts +9 -0
- package/dist/views/DealSidebar.d.ts.map +1 -0
- package/dist/views/LeadDetailView.d.ts +8 -0
- package/dist/views/LeadDetailView.d.ts.map +1 -0
- package/dist/views/LeadFormView.d.ts +5 -0
- package/dist/views/LeadFormView.d.ts.map +1 -0
- package/dist/views/LeadListView.d.ts +6 -0
- package/dist/views/LeadListView.d.ts.map +1 -0
- package/dist/views/PipelineView.d.ts +8 -0
- package/dist/views/PipelineView.d.ts.map +1 -0
- package/dist/views/QuoteDetailView.d.ts +8 -0
- package/dist/views/QuoteDetailView.d.ts.map +1 -0
- package/dist/views/QuoteFormView.d.ts +7 -0
- package/dist/views/QuoteFormView.d.ts.map +1 -0
- package/dist/views/QuoteListView.d.ts +7 -0
- package/dist/views/QuoteListView.d.ts.map +1 -0
- package/dist/views/dashboardWidgets.d.ts +11 -0
- package/dist/views/dashboardWidgets.d.ts.map +1 -0
- package/package.json +55 -0
- package/src/CrmContext.tsx +30 -0
- package/src/CrmPage.tsx +152 -0
- package/src/README.md +97 -0
- package/src/cascade.ts +24 -0
- package/src/components/CrmGeneralSettings.tsx +36 -0
- package/src/components/CrmOnboarding.tsx +52 -0
- package/src/components/PipelineSettings.tsx +45 -0
- package/src/components/QuoteStatusDropdown.tsx +214 -0
- package/src/data/index.ts +2 -0
- package/src/data/mock.ts +426 -0
- package/src/data/supabase.ts +634 -0
- package/src/data/types.ts +50 -0
- package/src/index.ts +240 -0
- package/src/lib/tenant.ts +4 -0
- package/src/locales/en.ts +292 -0
- package/src/locales/index.ts +7 -0
- package/src/locales/pt-BR.ts +292 -0
- package/src/migrations/001_crm_base.sql +73 -0
- package/src/migrations/002_activities.sql +33 -0
- package/src/migrations/003_crm_views_rls.sql +61 -0
- package/src/migrations/004_seed_default_pipeline.sql +31 -0
- package/src/registries.ts +88 -0
- package/src/schema/index.ts +102 -0
- package/src/store.ts +375 -0
- package/src/types.ts +280 -0
- package/src/views/ActivityListView.tsx +183 -0
- package/src/views/DashboardView.tsx +12 -0
- package/src/views/DealSidebar.tsx +414 -0
- package/src/views/LeadDetailView.tsx +264 -0
- package/src/views/LeadFormView.tsx +56 -0
- package/src/views/LeadListView.tsx +81 -0
- package/src/views/PipelineView.tsx +299 -0
- package/src/views/QuoteDetailView.tsx +408 -0
- package/src/views/QuoteFormView.tsx +489 -0
- package/src/views/QuoteListView.tsx +101 -0
- package/src/views/dashboardWidgets.tsx +248 -0
package/src/CrmPage.tsx
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import React, { useState, useMemo } from 'react'
|
|
2
|
+
import type { StoreApi } from 'zustand/vanilla'
|
|
3
|
+
import { useTranslation } from '@fayz-ai/core'
|
|
4
|
+
import { ModulePage, PageTransition, type ModuleNavItem } from '@fayz-ai/ui'
|
|
5
|
+
import { CrmContextProvider, type ResolvedCrmConfig } from './CrmContext'
|
|
6
|
+
import type { CrmDataProvider } from './data/types'
|
|
7
|
+
import type { CrmUIState } from './store'
|
|
8
|
+
import type { PluginRegistryDef, PluginQuickAction } from '@fayz-ai/core'
|
|
9
|
+
import { useModuleNavigation, ModuleActionBar, createViewRouter } from '@fayz-ai/saas'
|
|
10
|
+
import { CrmGeneralSettings } from './components/CrmGeneralSettings'
|
|
11
|
+
import { PipelineSettings } from './components/PipelineSettings'
|
|
12
|
+
import { CrmOnboarding } from './components/CrmOnboarding'
|
|
13
|
+
import { DashboardView } from './views/DashboardView'
|
|
14
|
+
import { PipelineView } from './views/PipelineView'
|
|
15
|
+
import { LeadListView } from './views/LeadListView'
|
|
16
|
+
import { LeadFormView } from './views/LeadFormView'
|
|
17
|
+
import { QuoteListView } from './views/QuoteListView'
|
|
18
|
+
import { QuoteFormView } from './views/QuoteFormView'
|
|
19
|
+
import { QuoteDetailView } from './views/QuoteDetailView'
|
|
20
|
+
import { LeadDetailView } from './views/LeadDetailView'
|
|
21
|
+
import { ActivityListView } from './views/ActivityListView'
|
|
22
|
+
|
|
23
|
+
function buildNav(config: ResolvedCrmConfig, view: string, navigate: (v: string) => void): ModuleNavItem[] {
|
|
24
|
+
const items: ModuleNavItem[] = [
|
|
25
|
+
{ id: 'dashboard', label: config.labels.dashboard, icon: 'BarChart3', active: view === 'dashboard', onClick: () => navigate('dashboard') },
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
if (config.modules.pipeline) {
|
|
29
|
+
items.push({ id: 'pipeline', label: config.labels.pipeline, icon: 'Filter', active: view === 'pipeline', onClick: () => navigate('pipeline') })
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
items.push({
|
|
33
|
+
id: 'leads', label: config.labels.leads, icon: 'UserPlus',
|
|
34
|
+
children: [
|
|
35
|
+
{ id: 'leads-new', label: config.labels.leadsNew, active: view === 'leads-new', onClick: () => navigate('leads-new') },
|
|
36
|
+
{ id: 'leads-list', label: config.labels.leadsList, active: view === 'leads-list' || view.startsWith('leads-detail:'), onClick: () => navigate('leads-list') },
|
|
37
|
+
],
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
if (config.modules.quotes) {
|
|
41
|
+
items.push({
|
|
42
|
+
id: 'quotes', label: config.labels.quotes, icon: 'FileText',
|
|
43
|
+
children: [
|
|
44
|
+
{ id: 'quotes-new', label: config.labels.quotesNew, active: view === 'quotes-new', onClick: () => navigate('quotes-new') },
|
|
45
|
+
{ id: 'quotes-list', label: config.labels.quotesList, active: view === 'quotes-list' || view.startsWith('quotes-detail:') || view.startsWith('quotes-edit:'), onClick: () => navigate('quotes-list') },
|
|
46
|
+
],
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (config.modules.activities) {
|
|
51
|
+
items.push({ id: 'activities', label: config.labels.activities, icon: 'MessageCircle', active: view === 'activities', onClick: () => navigate('activities') })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return items
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function CrmPage({ config, provider, store, registries }: {
|
|
58
|
+
config: ResolvedCrmConfig
|
|
59
|
+
provider: CrmDataProvider
|
|
60
|
+
store: StoreApi<CrmUIState>
|
|
61
|
+
registries?: PluginRegistryDef[]
|
|
62
|
+
}) {
|
|
63
|
+
const { view, direction, navigate } = useModuleNavigation('/sales', {
|
|
64
|
+
dashboard: 0, pipeline: 0,
|
|
65
|
+
'leads-list': 0, 'leads-new': 1, 'leads-detail': 1,
|
|
66
|
+
'quotes-list': 0, 'quotes-new': 1, 'quotes-detail': 1, 'quotes-edit': 2,
|
|
67
|
+
activities: 0,
|
|
68
|
+
settings: 1,
|
|
69
|
+
}, 'dashboard')
|
|
70
|
+
|
|
71
|
+
const [onboardingComplete, setOnboardingComplete] = useState(() => {
|
|
72
|
+
try { return localStorage.getItem('saas-core:crm-onboarded') === 'true' } catch { return false }
|
|
73
|
+
})
|
|
74
|
+
const isSettings = view === 'settings'
|
|
75
|
+
const isSummary = view === 'dashboard'
|
|
76
|
+
const nav = buildNav(config, view, navigate)
|
|
77
|
+
|
|
78
|
+
const t = useTranslation()
|
|
79
|
+
|
|
80
|
+
const quickActions = useMemo<PluginQuickAction[]>(() => [
|
|
81
|
+
{ id: 'new-lead', label: t('crm.quickActions.newLead'), icon: 'UserPlus', description: t('crm.quickActions.newLeadDesc'), action: () => navigate('leads-new') },
|
|
82
|
+
{ id: 'new-deal', label: t('crm.quickActions.newDeal'), icon: 'Target', description: t('crm.quickActions.newDealDesc'), action: () => navigate('pipeline') },
|
|
83
|
+
...(config.modules.quotes ? [{ id: 'new-quote', label: t('crm.quickActions.newQuote'), icon: 'FileText', description: t('crm.quickActions.newQuoteDesc'), action: () => navigate('quotes-new') }] : []),
|
|
84
|
+
...(config.modules.activities ? [{ id: 'log-activity', label: t('crm.quickActions.logActivity'), icon: 'MessageCircle', description: t('crm.quickActions.logActivityDesc'), action: () => navigate('activities') }] : []),
|
|
85
|
+
], [config.modules])
|
|
86
|
+
|
|
87
|
+
if (!onboardingComplete) {
|
|
88
|
+
return (
|
|
89
|
+
<CrmContextProvider config={config} provider={provider} store={store}>
|
|
90
|
+
<CrmOnboarding onComplete={() => { setOnboardingComplete(true); try { localStorage.setItem('saas-core:crm-onboarded', 'true') } catch {} }} />
|
|
91
|
+
</CrmContextProvider>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (isSettings && registries && registries.length > 0) {
|
|
96
|
+
return (
|
|
97
|
+
<CrmContextProvider config={config} provider={provider} store={store}>
|
|
98
|
+
<PageTransition transitionKey="settings" direction={direction}>
|
|
99
|
+
<div style={{ padding: '24px', display: 'flex', flexDirection: 'column', gap: '20px' }}>
|
|
100
|
+
<div>
|
|
101
|
+
<h1 style={{ fontSize: '20px', fontWeight: 600, margin: 0 }}>{t('crm.settingsPage.title')}</h1>
|
|
102
|
+
<p style={{ color: 'var(--muted-foreground, #6b7280)', margin: '4px 0 0', fontSize: '14px' }}>
|
|
103
|
+
{t('crm.settingsPage.subtitle')}
|
|
104
|
+
</p>
|
|
105
|
+
</div>
|
|
106
|
+
<CrmGeneralSettings />
|
|
107
|
+
<PipelineSettings />
|
|
108
|
+
</div>
|
|
109
|
+
</PageTransition>
|
|
110
|
+
</CrmContextProvider>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const renderView = createViewRouter([
|
|
115
|
+
{ id: 'pipeline', render: () => <PipelineView onViewLead={(id) => navigate(`leads-detail:${id}`)} onViewQuote={(id) => navigate(`quotes-detail:${id}`)} onAddLead={() => navigate('leads-new')} /> },
|
|
116
|
+
{ id: 'leads-list', render: () => <LeadListView onNew={() => navigate('leads-new')} onEdit={(id) => navigate(`leads-detail:${id}`)} /> },
|
|
117
|
+
{ id: 'leads-new', render: () => <LeadFormView onSaved={(id) => id ? navigate(`leads-detail:${id}`) : navigate('leads-list')} /> },
|
|
118
|
+
{ id: 'quotes-new', render: () => {
|
|
119
|
+
const hashParams = new URLSearchParams(window.location.hash.split('?')[1] ?? '')
|
|
120
|
+
const lid = hashParams.get('leadId') ?? undefined
|
|
121
|
+
return <QuoteFormView leadId={lid} onSaved={(id) => id ? navigate(`quotes-detail:${id}`) : navigate('quotes-list')} />
|
|
122
|
+
} },
|
|
123
|
+
{ id: 'quotes-list', render: () => <QuoteListView onNew={() => navigate('quotes-new')} onEdit={(id) => navigate(`quotes-detail:${id}`)} onEditQuote={(id) => navigate(`quotes-edit:${id}`)} /> },
|
|
124
|
+
{ id: 'activities', render: () => <ActivityListView /> },
|
|
125
|
+
{ id: 'leads-detail', render: ({ id }) => <LeadDetailView leadId={id!} onBack={() => navigate('leads-list')} onCreateQuote={(lid) => navigate('quotes-new', `/sales/quotes/new?leadId=${lid}`)} onViewQuote={(qid) => navigate(`quotes-detail:${qid}`)} /> },
|
|
126
|
+
{ id: 'quotes-detail', render: ({ id }) => <QuoteDetailView quoteId={id!} onBack={() => navigate('quotes-list')} onEdit={() => navigate(`quotes-edit:${id}`)} onInvoiceCreated={(invoiceId) => { window.location.hash = `/financial/receivables/detail/${invoiceId}` }} /> },
|
|
127
|
+
{ id: 'quotes-edit', render: ({ id }) => <QuoteFormView quoteId={id!} onSaved={() => navigate(`quotes-detail:${id}`)} /> },
|
|
128
|
+
{ id: 'dashboard', render: () => <DashboardView /> },
|
|
129
|
+
], 'dashboard')
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<CrmContextProvider config={config} provider={provider} store={store}>
|
|
133
|
+
<ModulePage
|
|
134
|
+
title={config.labels.pageTitle}
|
|
135
|
+
subtitle={config.labels.pageSubtitle}
|
|
136
|
+
nav={nav}
|
|
137
|
+
showHeader={isSummary}
|
|
138
|
+
viewKey={view}
|
|
139
|
+
direction={direction}
|
|
140
|
+
headerAction={
|
|
141
|
+
<ModuleActionBar
|
|
142
|
+
quickActions={quickActions}
|
|
143
|
+
settingsPath={registries && registries.length > 0 ? '/settings/crm' : undefined}
|
|
144
|
+
settingsLabel="CRM Settings"
|
|
145
|
+
/>
|
|
146
|
+
}
|
|
147
|
+
>
|
|
148
|
+
{renderView(view)}
|
|
149
|
+
</ModulePage>
|
|
150
|
+
</CrmContextProvider>
|
|
151
|
+
)
|
|
152
|
+
}
|
package/src/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Sales & CRM Plugin
|
|
2
|
+
|
|
3
|
+
Lead management, sales pipeline, deal tracking, quotes, and activity logging for any SaaS vertical.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { createCrmPlugin } from '@fayz-ai/saas-core/plugins/crm'
|
|
9
|
+
|
|
10
|
+
plugins: [
|
|
11
|
+
createCrmPlugin({
|
|
12
|
+
currency: { code: 'BRL', locale: 'pt-BR', symbol: 'R$' },
|
|
13
|
+
}),
|
|
14
|
+
]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
| Option | Type | Default | Description |
|
|
20
|
+
|--------|------|---------|-------------|
|
|
21
|
+
| `modules.pipeline` | boolean | true | Visual kanban deal board |
|
|
22
|
+
| `modules.quotes` | boolean | true | Quote management |
|
|
23
|
+
| `modules.activities` | boolean | true | Activity logging |
|
|
24
|
+
| `modules.contacts` | boolean | true | Contact segmentation |
|
|
25
|
+
| `currency` | object | BRL/pt-BR | Currency formatting |
|
|
26
|
+
| `dealStages` | array | 7 default stages | Custom pipeline stages |
|
|
27
|
+
| `itemTypes` | array | service, product, other | Quote line item types |
|
|
28
|
+
| `leadSources` | array | — | Custom lead sources |
|
|
29
|
+
| `dataProvider` | CrmDataProvider | mock | Custom data provider |
|
|
30
|
+
| `navPosition` | number | 5 | Navigation order |
|
|
31
|
+
|
|
32
|
+
## Architecture
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
src/plugins/crm/
|
|
36
|
+
index.ts # createCrmPlugin() factory
|
|
37
|
+
types.ts # Pipeline, Lead, Deal, Activity, Quote types
|
|
38
|
+
registries.ts # Lead Sources, Tags, Activity Types
|
|
39
|
+
store.ts # Zustand UI state
|
|
40
|
+
CrmContext.tsx # React contexts + hooks
|
|
41
|
+
CrmPage.tsx # Main page with ModulePage layout
|
|
42
|
+
data/ # Provider interface + mock
|
|
43
|
+
views/ # Dashboard, Pipeline, Leads, Quotes, Activities, Contacts
|
|
44
|
+
components/ # Settings, GeneralSettings, Onboarding
|
|
45
|
+
migrations/ # SQL files
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Type System
|
|
49
|
+
|
|
50
|
+
| Entity | Purpose |
|
|
51
|
+
|--------|---------|
|
|
52
|
+
| `Pipeline` | Named pipeline with stages |
|
|
53
|
+
| `PipelineStage` | Stage with order, color, probability, won/lost flags |
|
|
54
|
+
| `Lead` | Contact with source, status, value, tags |
|
|
55
|
+
| `Deal` | Opportunity in pipeline with stage, value, probability |
|
|
56
|
+
| `Activity` | Interaction log: call, email, meeting, note, task |
|
|
57
|
+
| `Quote` | Proposal with line items, status lifecycle |
|
|
58
|
+
| `Tag` | Colored label for organizing leads/deals |
|
|
59
|
+
| `LeadSource` | Where leads come from |
|
|
60
|
+
|
|
61
|
+
### Pipeline Stages (default)
|
|
62
|
+
|
|
63
|
+
New → Contacted → Qualified → Proposal → Negotiation → Won / Lost
|
|
64
|
+
|
|
65
|
+
### Lead Status Flow
|
|
66
|
+
|
|
67
|
+
new → contacted → qualified → converted (to deal) / unqualified / lost
|
|
68
|
+
|
|
69
|
+
### Quote Lifecycle
|
|
70
|
+
|
|
71
|
+
draft → sent → approved / rejected / expired
|
|
72
|
+
|
|
73
|
+
## Settings
|
|
74
|
+
|
|
75
|
+
Plugin settings have two sections:
|
|
76
|
+
|
|
77
|
+
**General** — Module toggles, lead management config, deal behavior
|
|
78
|
+
**Registries** — Lead Sources (seeded), Tags (editable), Activity Types (read-only)
|
|
79
|
+
|
|
80
|
+
## Views
|
|
81
|
+
|
|
82
|
+
| View | Route | Description |
|
|
83
|
+
|------|-------|-------------|
|
|
84
|
+
| Dashboard | `/sales` | KPIs, funnel chart, won deals |
|
|
85
|
+
| Pipeline | `/sales/pipeline` | Kanban board by stage |
|
|
86
|
+
| Lead List | `/sales/leads/list` | Filterable by status/source |
|
|
87
|
+
| Lead Form | `/sales/leads/new` | Capture new lead |
|
|
88
|
+
| Quotes | `/sales/quotes/list` | Quote management |
|
|
89
|
+
| Activities | `/sales/activities` | Activity log |
|
|
90
|
+
| Contacts | `/sales/contacts/*` | Active/Inactive/VIP segments |
|
|
91
|
+
| Settings | `/sales/settings/*` | General + Registries |
|
|
92
|
+
|
|
93
|
+
## Database Migrations
|
|
94
|
+
|
|
95
|
+
1. `001_crm_base.sql` — pipelines, pipeline_stages, lead_sources, crm_tags, leads, deals
|
|
96
|
+
2. `002_quotes.sql` — crm_quotes, crm_quote_items
|
|
97
|
+
3. `003_activities.sql` — crm_activity_types, crm_activities
|
package/src/cascade.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PipelineStage, LeadStatus, QuoteStatus } from './types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Derives the lead status from the pipeline stage the deal is in.
|
|
5
|
+
* Pipeline stages are the single source of truth for lead lifecycle.
|
|
6
|
+
*/
|
|
7
|
+
export function deriveLeadStatus(stage: PipelineStage): LeadStatus {
|
|
8
|
+
if (stage.isWon) return 'converted'
|
|
9
|
+
if (stage.isLost) return 'lost'
|
|
10
|
+
if (stage.probability <= 10) return 'new'
|
|
11
|
+
if (stage.probability <= 25) return 'contacted'
|
|
12
|
+
return 'qualified'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Derives the quote status from the pipeline stage.
|
|
17
|
+
* Never downgrades — if the quote is already 'sent', moving the deal
|
|
18
|
+
* backward won't revert it to 'draft'.
|
|
19
|
+
*/
|
|
20
|
+
export function deriveQuoteStatus(stage: PipelineStage, current: QuoteStatus): QuoteStatus {
|
|
21
|
+
if (stage.isWon) return 'approved'
|
|
22
|
+
if (stage.isLost) return 'rejected'
|
|
23
|
+
return current
|
|
24
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { SettingsGroup, ToggleRow } from '@fayz-ai/saas'
|
|
3
|
+
import { useTranslation } from '@fayz-ai/core'
|
|
4
|
+
|
|
5
|
+
export function CrmGeneralSettings() {
|
|
6
|
+
const t = useTranslation()
|
|
7
|
+
return (
|
|
8
|
+
<div className="space-y-4">
|
|
9
|
+
<SettingsGroup title={t('crm.settings.leadManagement')} description={t('crm.settings.leadManagementDesc')}>
|
|
10
|
+
<ToggleRow label={t('crm.settings.autoAssign')} description={t('crm.settings.autoAssignDesc')} checked={false} onChange={() => {}} />
|
|
11
|
+
<ToggleRow label={t('crm.settings.requireSource')} description={t('crm.settings.requireSourceDesc')} checked={true} onChange={() => {}} />
|
|
12
|
+
<ToggleRow label={t('crm.settings.leadScoring')} description={t('crm.settings.leadScoringDesc')} checked={false} onChange={() => {}} />
|
|
13
|
+
<ToggleRow label={t('crm.settings.duplicateDetection')} description={t('crm.settings.duplicateDetectionDesc')} checked={true} onChange={() => {}} />
|
|
14
|
+
</SettingsGroup>
|
|
15
|
+
|
|
16
|
+
<SettingsGroup title={t('crm.settings.deals')} description={t('crm.settings.dealsDesc')}>
|
|
17
|
+
<ToggleRow label={t('crm.settings.autoCreateDeal')} description={t('crm.settings.autoCreateDealDesc')} checked={true} onChange={() => {}} />
|
|
18
|
+
<ToggleRow label={t('crm.settings.requireCloseDate')} description={t('crm.settings.requireCloseDateDesc')} checked={false} onChange={() => {}} />
|
|
19
|
+
<ToggleRow label={t('crm.settings.rottingDeals')} description={t('crm.settings.rottingDealsDesc')} checked={true} onChange={() => {}} />
|
|
20
|
+
<ToggleRow label={t('crm.settings.weightedPipeline')} description={t('crm.settings.weightedPipelineDesc')} checked={true} onChange={() => {}} />
|
|
21
|
+
</SettingsGroup>
|
|
22
|
+
|
|
23
|
+
<SettingsGroup title={t('crm.settings.quotes')} description={t('crm.settings.quotesDesc')}>
|
|
24
|
+
<ToggleRow label={t('crm.settings.autoNumberQuotes')} description={t('crm.settings.autoNumberQuotesDesc')} checked={true} onChange={() => {}} />
|
|
25
|
+
<ToggleRow label={t('crm.settings.defaultValidity')} description={t('crm.settings.defaultValidityDesc')} checked={true} onChange={() => {}} />
|
|
26
|
+
<ToggleRow label={t('crm.settings.requireApproval')} description={t('crm.settings.requireApprovalDesc')} checked={false} onChange={() => {}} />
|
|
27
|
+
</SettingsGroup>
|
|
28
|
+
|
|
29
|
+
<SettingsGroup title={t('crm.settings.notifications')} description={t('crm.settings.notificationsDesc')}>
|
|
30
|
+
<ToggleRow label={t('crm.settings.overdueAlerts')} description={t('crm.settings.overdueAlertsDesc')} checked={true} onChange={() => {}} />
|
|
31
|
+
<ToggleRow label={t('crm.settings.stageChangeAlerts')} description={t('crm.settings.stageChangeAlertsDesc')} checked={false} onChange={() => {}} />
|
|
32
|
+
<ToggleRow label={t('crm.settings.newLeadNotif')} description={t('crm.settings.newLeadNotifDesc')} checked={true} onChange={() => {}} />
|
|
33
|
+
</SettingsGroup>
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { Filter, Globe, Target, ChevronRight, Check } from 'lucide-react'
|
|
3
|
+
import { useTranslation } from '@fayz-ai/core'
|
|
4
|
+
import { Button } from '@fayz-ai/ui'
|
|
5
|
+
|
|
6
|
+
const STEPS = [
|
|
7
|
+
{ id: 'welcome', icon: Filter, titleKey: 'crm.onboarding.welcome', descKey: 'crm.onboarding.description' },
|
|
8
|
+
{ id: 'sources', icon: Globe, titleKey: 'crm.onboarding.sources.title', descKey: 'crm.onboarding.sources.description' },
|
|
9
|
+
{ id: 'pipeline', icon: Target, titleKey: 'crm.onboarding.pipeline.title', descKey: 'crm.onboarding.pipeline.description' },
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
export function CrmOnboarding({ onComplete }: { onComplete: () => void }) {
|
|
13
|
+
const t = useTranslation()
|
|
14
|
+
const [step, setStep] = useState(0)
|
|
15
|
+
const current = STEPS[step]
|
|
16
|
+
const isLast = step === STEPS.length - 1
|
|
17
|
+
const Icon = current.icon
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div className="flex items-center justify-center py-12">
|
|
21
|
+
<div className="w-full max-w-lg">
|
|
22
|
+
<div className="flex items-center gap-1 mb-8">
|
|
23
|
+
{STEPS.map((_, i) => <div key={i} className={`h-1 flex-1 rounded-full transition-colors ${i <= step ? 'bg-primary' : 'bg-muted'}`} />)}
|
|
24
|
+
</div>
|
|
25
|
+
<div className="rounded-card border bg-card p-8 text-center space-y-6 shadow-sm">
|
|
26
|
+
<div className="flex justify-center">
|
|
27
|
+
<div className="flex h-16 w-16 items-center justify-center rounded-2xl bg-primary/10">
|
|
28
|
+
<Icon className="h-8 w-8 text-primary" />
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
<div>
|
|
32
|
+
<h2 className="text-xl font-bold">{t(current.titleKey)}</h2>
|
|
33
|
+
<p className="text-sm text-muted-foreground mt-2 max-w-sm mx-auto">{t(current.descKey)}</p>
|
|
34
|
+
</div>
|
|
35
|
+
<div className="flex items-center justify-center gap-3 pt-2">
|
|
36
|
+
{step > 0 && <Button variant="outline" size="lg" onClick={() => setStep(step - 1)}>{t('common.back')}</Button>}
|
|
37
|
+
{isLast ? (
|
|
38
|
+
<Button variant="default" size="lg" onClick={onComplete}>
|
|
39
|
+
<Check className="h-4 w-4" /> {t('crm.onboarding.startSelling')}
|
|
40
|
+
</Button>
|
|
41
|
+
) : (
|
|
42
|
+
<Button variant="default" size="lg" onClick={() => setStep(step + 1)}>
|
|
43
|
+
{step === 0 ? t('crm.onboarding.getStarted') : t('crm.onboarding.next')} <ChevronRight className="h-4 w-4" />
|
|
44
|
+
</Button>
|
|
45
|
+
)}
|
|
46
|
+
</div>
|
|
47
|
+
{step === 0 && <button onClick={onComplete} className="text-xs text-muted-foreground hover:text-foreground transition-colors">{t('crm.onboarding.skip')}</button>}
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { useEffect } from 'react'
|
|
2
|
+
import { useCrmStore } from '../CrmContext'
|
|
3
|
+
import { SettingsGroup } from '@fayz-ai/saas'
|
|
4
|
+
import { useTranslation } from '@fayz-ai/core'
|
|
5
|
+
|
|
6
|
+
export function PipelineSettings() {
|
|
7
|
+
const t = useTranslation()
|
|
8
|
+
const stages = useCrmStore((s) => s.stages)
|
|
9
|
+
const pipelines = useCrmStore((s) => s.pipelines)
|
|
10
|
+
const fetchPipelines = useCrmStore((s) => s.fetchPipelines)
|
|
11
|
+
|
|
12
|
+
useEffect(() => { fetchPipelines() }, [])
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div className="space-y-4">
|
|
16
|
+
<SettingsGroup title={t('crm.pipelineSettings.title')} description={t('crm.pipelineSettings.description')}>
|
|
17
|
+
{stages.length === 0 ? (
|
|
18
|
+
<div className="py-6 text-center text-sm text-muted-foreground">{t('common.loading')}</div>
|
|
19
|
+
) : (
|
|
20
|
+
<div className="space-y-0">
|
|
21
|
+
{stages.map((stage, i) => (
|
|
22
|
+
<div key={stage.id} className="flex items-center gap-3 py-3">
|
|
23
|
+
<span className="text-xs text-muted-foreground w-5 shrink-0">{i + 1}</span>
|
|
24
|
+
<div className="h-3 w-3 rounded-full shrink-0" style={{ backgroundColor: stage.color }} />
|
|
25
|
+
<div className="flex-1 min-w-0">
|
|
26
|
+
<p className="text-sm font-medium">{stage.name}</p>
|
|
27
|
+
<p className="text-[10px] text-muted-foreground">
|
|
28
|
+
{t('crm.pipelineSettings.probability')}: {stage.probability}%
|
|
29
|
+
{stage.isWon && ` — ${t('crm.pipelineSettings.winStage')}`}
|
|
30
|
+
{stage.isLost && ` — ${t('crm.pipelineSettings.lossStage')}`}
|
|
31
|
+
</p>
|
|
32
|
+
</div>
|
|
33
|
+
<span className="text-xs text-muted-foreground">{stage.probability}%</span>
|
|
34
|
+
</div>
|
|
35
|
+
))}
|
|
36
|
+
</div>
|
|
37
|
+
)}
|
|
38
|
+
</SettingsGroup>
|
|
39
|
+
|
|
40
|
+
<p className="text-[10px] text-muted-foreground px-1">
|
|
41
|
+
{t('crm.pipelineSettings.customizationNote')}
|
|
42
|
+
</p>
|
|
43
|
+
</div>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { createPortal } from 'react-dom'
|
|
3
|
+
import { ChevronDown, Loader2, Send, CircleDashed, CircleCheckBig, CircleAlert, Ban } from 'lucide-react'
|
|
4
|
+
import { Dropdown, DropdownTrigger, DropdownContent, DropdownItem, DropdownLabel, DropdownSeparator } from '@fayz-ai/ui'
|
|
5
|
+
import { ConfirmDialog } from '@fayz-ai/ui'
|
|
6
|
+
import { Button } from '@fayz-ai/ui'
|
|
7
|
+
import { useCrmStore } from '../CrmContext'
|
|
8
|
+
import type { Quote, QuoteStatus } from '../types'
|
|
9
|
+
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Status config
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
const STATUS_CONFIG: Record<QuoteStatus, { bg: string; dot: string; icon: React.ElementType; label: string }> = {
|
|
15
|
+
draft: { bg: 'bg-muted text-muted-foreground', dot: 'bg-muted-foreground', icon: CircleDashed, label: 'Draft' },
|
|
16
|
+
sent: { bg: 'bg-info-soft text-info-soft-foreground', dot: 'bg-info', icon: Send, label: 'Sent' },
|
|
17
|
+
approved: { bg: 'bg-success-soft text-success-soft-foreground', dot: 'bg-success', icon: CircleCheckBig, label: 'Approved' },
|
|
18
|
+
rejected: { bg: 'bg-destructive-soft text-destructive-soft-foreground', dot: 'bg-destructive', icon: Ban, label: 'Rejected' },
|
|
19
|
+
expired: { bg: 'bg-warning-soft text-warning-soft-foreground', dot: 'bg-warning', icon: CircleAlert, label: 'Expired' },
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const TRANSITIONS: Record<QuoteStatus, QuoteStatus[]> = {
|
|
23
|
+
draft: ['sent', 'expired'],
|
|
24
|
+
sent: ['approved', 'rejected', 'expired'],
|
|
25
|
+
approved: [],
|
|
26
|
+
rejected: [],
|
|
27
|
+
expired: [],
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Rejection reason modal
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
function RejectModal({ onConfirm, onCancel }: { onConfirm: (reason: string) => void; onCancel: () => void }) {
|
|
35
|
+
const [reason, setReason] = useState('')
|
|
36
|
+
|
|
37
|
+
return createPortal(
|
|
38
|
+
<div className="fixed inset-0 z-[60] flex items-center justify-center bg-black/50" onClick={onCancel}>
|
|
39
|
+
<div
|
|
40
|
+
className="w-full max-w-sm rounded-modal border bg-card shadow-lg mx-4 p-5"
|
|
41
|
+
onClick={(e) => e.stopPropagation()}
|
|
42
|
+
style={{ animation: 'saas-sheet-fade-in 150ms ease-out' }}
|
|
43
|
+
>
|
|
44
|
+
<div className="mb-3">
|
|
45
|
+
<h3 className="text-sm font-semibold">Reject Quote</h3>
|
|
46
|
+
<p className="text-xs text-muted-foreground mt-0.5">Provide a reason for the rejection.</p>
|
|
47
|
+
</div>
|
|
48
|
+
<textarea
|
|
49
|
+
value={reason}
|
|
50
|
+
onChange={(e) => setReason(e.target.value)}
|
|
51
|
+
rows={3}
|
|
52
|
+
placeholder="Reason for rejection..."
|
|
53
|
+
autoFocus
|
|
54
|
+
className="w-full rounded-input border border-input bg-card px-3 py-2 text-sm shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] focus:outline-none focus:ring-2 focus:ring-ring resize-none"
|
|
55
|
+
/>
|
|
56
|
+
<div className="flex justify-end gap-2 mt-3">
|
|
57
|
+
<Button variant="outline" size="sm" onClick={onCancel}>
|
|
58
|
+
Cancel
|
|
59
|
+
</Button>
|
|
60
|
+
<Button variant="destructive" size="sm" onClick={() => onConfirm(reason)} disabled={!reason.trim()}>
|
|
61
|
+
Reject Quote
|
|
62
|
+
</Button>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
</div>,
|
|
66
|
+
document.body
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// QuoteStatusDropdown
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
|
|
74
|
+
export function QuoteStatusDropdown({ quote, onStatusChange, size = 'default' }: {
|
|
75
|
+
quote: Quote
|
|
76
|
+
onStatusChange?: (q: Quote) => void
|
|
77
|
+
size?: 'sm' | 'default'
|
|
78
|
+
}) {
|
|
79
|
+
const sendQuote = useCrmStore((s) => s.sendQuote)
|
|
80
|
+
const approveQuote = useCrmStore((s) => s.approveQuote)
|
|
81
|
+
const rejectQuote = useCrmStore((s) => s.rejectQuote)
|
|
82
|
+
const expireQuote = useCrmStore((s) => s.expireQuote)
|
|
83
|
+
|
|
84
|
+
const [loading, setLoading] = useState(false)
|
|
85
|
+
const [showApprove, setShowApprove] = useState(false)
|
|
86
|
+
const [showReject, setShowReject] = useState(false)
|
|
87
|
+
|
|
88
|
+
const config = STATUS_CONFIG[quote.status] ?? STATUS_CONFIG.draft
|
|
89
|
+
const StatusIcon = config.icon
|
|
90
|
+
const transitions = TRANSITIONS[quote.status] ?? []
|
|
91
|
+
|
|
92
|
+
async function handleTransition(target: QuoteStatus) {
|
|
93
|
+
if (loading) return
|
|
94
|
+
setLoading(true)
|
|
95
|
+
try {
|
|
96
|
+
let updated: Quote
|
|
97
|
+
switch (target) {
|
|
98
|
+
case 'sent':
|
|
99
|
+
updated = await sendQuote(quote.id)
|
|
100
|
+
break
|
|
101
|
+
case 'approved':
|
|
102
|
+
setShowApprove(true)
|
|
103
|
+
setLoading(false)
|
|
104
|
+
return
|
|
105
|
+
case 'expired':
|
|
106
|
+
updated = await expireQuote(quote.id)
|
|
107
|
+
break
|
|
108
|
+
default:
|
|
109
|
+
setLoading(false)
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
onStatusChange?.(updated)
|
|
113
|
+
} catch {
|
|
114
|
+
// toast handled by store
|
|
115
|
+
} finally {
|
|
116
|
+
setLoading(false)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function handleReject(reason: string) {
|
|
121
|
+
setShowReject(false)
|
|
122
|
+
setLoading(true)
|
|
123
|
+
try {
|
|
124
|
+
const updated = await rejectQuote(quote.id, reason)
|
|
125
|
+
onStatusChange?.(updated)
|
|
126
|
+
} catch {
|
|
127
|
+
// toast handled by store
|
|
128
|
+
} finally {
|
|
129
|
+
setLoading(false)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const isSmall = size === 'sm'
|
|
134
|
+
|
|
135
|
+
// Terminal states — static badge, no dropdown
|
|
136
|
+
if (transitions.length === 0) {
|
|
137
|
+
return (
|
|
138
|
+
<span className={`inline-flex items-center gap-1 rounded-full font-medium capitalize ${config.bg} ${isSmall ? 'px-1.5 py-0.5 text-[9px]' : 'px-2.5 py-1 text-[11px]'}`}>
|
|
139
|
+
{!isSmall && <StatusIcon className="h-3 w-3" />}
|
|
140
|
+
{config.label}
|
|
141
|
+
</span>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<>
|
|
147
|
+
<Dropdown>
|
|
148
|
+
<DropdownTrigger asChild>
|
|
149
|
+
<button
|
|
150
|
+
onClick={(e) => e.stopPropagation()}
|
|
151
|
+
disabled={loading}
|
|
152
|
+
className={`inline-flex items-center gap-1 rounded-full font-medium capitalize transition-all ${config.bg} ${
|
|
153
|
+
isSmall ? 'px-1.5 py-0.5 text-[9px]' : 'px-2.5 py-1 text-[11px]'
|
|
154
|
+
} hover:ring-2 hover:ring-primary/20 focus:outline-none focus:ring-2 focus:ring-ring`}
|
|
155
|
+
>
|
|
156
|
+
{!isSmall && <StatusIcon className="h-3 w-3" />}
|
|
157
|
+
{config.label}
|
|
158
|
+
{loading ? (
|
|
159
|
+
<Loader2 className={`animate-spin ${isSmall ? 'h-2.5 w-2.5' : 'h-3 w-3'}`} />
|
|
160
|
+
) : (
|
|
161
|
+
<ChevronDown className={`opacity-50 ${isSmall ? 'h-2.5 w-2.5' : 'h-3 w-3'}`} />
|
|
162
|
+
)}
|
|
163
|
+
</button>
|
|
164
|
+
</DropdownTrigger>
|
|
165
|
+
<DropdownContent align="end" sideOffset={4} onClick={(e: React.MouseEvent) => e.stopPropagation()}>
|
|
166
|
+
<DropdownLabel>Change status</DropdownLabel>
|
|
167
|
+
<DropdownSeparator />
|
|
168
|
+
{transitions.map((target) => {
|
|
169
|
+
const t = STATUS_CONFIG[target]
|
|
170
|
+
const TargetIcon = t.icon
|
|
171
|
+
return (
|
|
172
|
+
<DropdownItem
|
|
173
|
+
key={target}
|
|
174
|
+
onClick={() => target === 'rejected' ? setShowReject(true) : handleTransition(target)}
|
|
175
|
+
className="gap-2.5"
|
|
176
|
+
>
|
|
177
|
+
<span className={`h-2 w-2 rounded-full shrink-0 ${t.dot}`} />
|
|
178
|
+
<TargetIcon className="h-3.5 w-3.5 shrink-0" />
|
|
179
|
+
<span>{t.label}</span>
|
|
180
|
+
</DropdownItem>
|
|
181
|
+
)
|
|
182
|
+
})}
|
|
183
|
+
</DropdownContent>
|
|
184
|
+
</Dropdown>
|
|
185
|
+
|
|
186
|
+
<ConfirmDialog
|
|
187
|
+
open={showApprove}
|
|
188
|
+
variant="success"
|
|
189
|
+
title="Approve this quote?"
|
|
190
|
+
description="This will create an invoice and convert the lead to a client. This action cannot be undone."
|
|
191
|
+
confirmLabel="Approve"
|
|
192
|
+
cancelLabel="Cancel"
|
|
193
|
+
loading={loading}
|
|
194
|
+
onConfirm={async () => {
|
|
195
|
+
setLoading(true)
|
|
196
|
+
try {
|
|
197
|
+
const updated = await approveQuote(quote.id)
|
|
198
|
+
setShowApprove(false)
|
|
199
|
+
onStatusChange?.(updated)
|
|
200
|
+
} catch {
|
|
201
|
+
// toast handled by store
|
|
202
|
+
} finally {
|
|
203
|
+
setLoading(false)
|
|
204
|
+
}
|
|
205
|
+
}}
|
|
206
|
+
onCancel={() => setShowApprove(false)}
|
|
207
|
+
/>
|
|
208
|
+
|
|
209
|
+
{showReject && (
|
|
210
|
+
<RejectModal onConfirm={handleReject} onCancel={() => setShowReject(false)} />
|
|
211
|
+
)}
|
|
212
|
+
</>
|
|
213
|
+
)
|
|
214
|
+
}
|