@ossy/consultancy 3.20.1 → 3.22.0

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.
Files changed (48) hide show
  1. package/package.json +4 -2
  2. package/src/AssignmentMarginCalculator.jsx +7 -32
  3. package/src/ConsultancyNav.jsx +30 -1
  4. package/src/ConsultancyRecordList.jsx +172 -0
  5. package/src/CreateConsultancyButton.jsx +61 -13
  6. package/src/Forecast.jsx +42 -220
  7. package/src/Overview.jsx +10 -31
  8. package/src/RequestStatsPanel.jsx +66 -0
  9. package/src/consultancy.page.jsx +3 -40
  10. package/src/contracts.page.jsx +26 -0
  11. package/src/current-month.component.jsx +43 -25
  12. package/src/employees.page.jsx +26 -0
  13. package/src/en.translations.json +67 -2
  14. package/src/extract-request.action.js +5 -0
  15. package/src/extract-request.task.js +100 -0
  16. package/src/extract-request.task.spec.js +89 -0
  17. package/src/forecast-panels.jsx +125 -0
  18. package/src/forecast-widget-menu.jsx +89 -0
  19. package/src/get-request-stats.action.js +6 -0
  20. package/src/get-request-stats.task.js +26 -0
  21. package/src/index.js +1 -0
  22. package/src/intake-categories.js +39 -0
  23. package/src/kpi-trend.component.jsx +17 -0
  24. package/src/margin-panels.jsx +7 -32
  25. package/src/opportunities.page.jsx +26 -0
  26. package/src/opportunity.schema.js +1 -1
  27. package/src/org.page.jsx +1 -2
  28. package/src/proposals.page.jsx +26 -0
  29. package/src/reports.page.jsx +103 -0
  30. package/src/request-buckets.js +76 -0
  31. package/src/request-buckets.spec.js +33 -0
  32. package/src/request-stats.aggregate.js +52 -0
  33. package/src/request-stats.aggregate.spec.js +34 -0
  34. package/src/request-stats.component.jsx +16 -0
  35. package/src/request.schema.js +29 -0
  36. package/src/requests.page.jsx +26 -0
  37. package/src/schema-ids.js +1 -0
  38. package/src/screen-inbound.task.js +84 -0
  39. package/src/screen-inbound.task.spec.js +97 -0
  40. package/src/sv.translations.json +67 -2
  41. package/src/use-chart-months.js +27 -0
  42. package/src/utilization-hours.js +196 -0
  43. package/src/utilization-hours.spec.js +134 -0
  44. package/src/utilization.component.jsx +17 -0
  45. package/src/vacations.page.jsx +26 -0
  46. package/src/year-totals.component.jsx +17 -0
  47. package/src/forecast-kpi-chart.js +0 -137
  48. package/src/forecast-kpi-chart.spec.js +0 -122
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/consultancy",
3
3
  "description": "Consultancy feature package — schemas, forecasts UI, and assignment margins",
4
- "version": "3.20.1",
4
+ "version": "3.22.0",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
7
7
  "module": "./src/index.js",
@@ -25,12 +25,14 @@
25
25
  "README.md"
26
26
  ],
27
27
  "dependencies": {
28
+ "@ossy/event-store": "^3.20.1",
28
29
  "@ossy/schema": "^3.20.1"
29
30
  },
30
31
  "peerDependencies": {
31
32
  "@ossy/calendar": "*",
32
33
  "@ossy/dashboard": "*",
33
34
  "@ossy/design-system": "*",
35
+ "@ossy/resources": "*",
34
36
  "@ossy/router-react": "*",
35
37
  "@ossy/sdk-react": "*",
36
38
  "react": "*"
@@ -38,5 +40,5 @@
38
40
  "devDependencies": {
39
41
  "jest": "^30.2.0"
40
42
  },
41
- "gitHead": "3e8bb118b3ef163792a004663ccb803ab51a8601"
43
+ "gitHead": "29de300fd5e2c36f9d6d00f09eb9f1508997a904"
42
44
  }
@@ -1,5 +1,6 @@
1
1
  import React, { useEffect, useState } from 'react'
2
2
  import {
3
+ Panel,
3
4
  View,
4
5
  Text,
5
6
  Alert,
@@ -43,32 +44,6 @@ function parseNumber (value, fallback = 0) {
43
44
  return Number.isFinite(parsed) ? parsed : fallback
44
45
  }
45
46
 
46
- function SectionPanel ({ title, children, ...props }) {
47
- return (
48
- <View surface="primary" roundness="xs" style={{ minWidth: 0, overflow: 'hidden' }} {...props}>
49
- <View stack bordered>
50
- <View.Item
51
- data-surface="primary"
52
- layout="row"
53
- style={{
54
- alignItems: 'center',
55
- justifyContent: 'space-between',
56
- padding: 'var(--space-s) var(--space-m)',
57
- gap: 'var(--space-m)',
58
- height: '48px',
59
- flexShrink: 0,
60
- }}
61
- >
62
- <Text variant="small" as="h2" style={{ fontWeight: 'bold' }} text={title} />
63
- </View.Item>
64
- <View.Item>
65
- {children}
66
- </View.Item>
67
- </View>
68
- </View>
69
- )
70
- }
71
-
72
47
  function MetricRow ({ label, value }) {
73
48
  return (
74
49
  <View layout="row" justifyContent="space-between" gap="s">
@@ -157,15 +132,15 @@ export const AssignmentMarginCalculator = () => {
157
132
 
158
133
  <View layout="row-wrap" gap="m" style={{ alignItems: 'stretch' }}>
159
134
  <View style={{ flex: '1 1 320px', minWidth: 0 }}>
160
- <SectionPanel title="consultancy.margins.inputs.title">
135
+ <Panel title="consultancy.margins.inputs.title">
161
136
  <View inset="m" gap="m">
162
137
  <FieldFactory />
163
138
  </View>
164
- </SectionPanel>
139
+ </Panel>
165
140
  </View>
166
141
 
167
142
  <View style={{ flex: '1 1 320px', minWidth: 0 }}>
168
- <SectionPanel
143
+ <Panel
169
144
  title="consultancy.margins.results.title"
170
145
  data-margins-status={margin.isProfitable ? 'profitable' : 'unprofitable'}
171
146
  >
@@ -186,17 +161,17 @@ export const AssignmentMarginCalculator = () => {
186
161
  text={margin.coversEmployerCost ? 'consultancy.margins.results.coversCost' : 'consultancy.margins.results.missesCost'}
187
162
  />
188
163
  </View>
189
- </SectionPanel>
164
+ </Panel>
190
165
  </View>
191
166
  </View>
192
167
 
193
- <SectionPanel title="consultancy.margins.leakage.title" data-margins-leakage="on">
168
+ <Panel title="consultancy.margins.leakage.title" data-margins-leakage="on">
194
169
  <View gap="m" inset="m">
195
170
  <Text variant="small" color="secondary" text="consultancy.margins.leakage.description" />
196
171
  <MetricRow label="consultancy.margins.leakage.hours" value={hoursFormat(leakage.leakedHours)} />
197
172
  <MetricRow label="consultancy.margins.leakage.revenue" value={money(leakage.leakedRevenue)} />
198
173
  </View>
199
- </SectionPanel>
174
+ </Panel>
200
175
  </Form>
201
176
  )
202
177
  }
@@ -2,12 +2,40 @@ import React from 'react'
2
2
  import { Tabs } from '@ossy/design-system'
3
3
  import { useRouter } from '@ossy/router-react'
4
4
 
5
- /** Overview (home) first, Margins middle, Org Details last. */
5
+ /** Overview, then the sales records, then the people and the company. */
6
6
  const TABS = [
7
7
  {
8
8
  id: 'consultancy/home',
9
9
  label: 'consultancy.nav.overview',
10
10
  },
11
+ {
12
+ id: 'consultancy/requests',
13
+ label: 'consultancy.nav.requests',
14
+ },
15
+ {
16
+ id: 'consultancy/opportunities',
17
+ label: 'consultancy.nav.opportunities',
18
+ },
19
+ {
20
+ id: 'consultancy/proposals',
21
+ label: 'consultancy.nav.proposals',
22
+ },
23
+ {
24
+ id: 'consultancy/reports',
25
+ label: 'consultancy.nav.reports',
26
+ },
27
+ {
28
+ id: 'consultancy/employees',
29
+ label: 'consultancy.nav.employees',
30
+ },
31
+ {
32
+ id: 'consultancy/vacations',
33
+ label: 'consultancy.nav.vacations',
34
+ },
35
+ {
36
+ id: 'consultancy/contracts',
37
+ label: 'consultancy.nav.contracts',
38
+ },
11
39
  {
12
40
  id: 'consultancy/margins',
13
41
  label: 'consultancy.nav.margins',
@@ -34,6 +62,7 @@ export function ConsultancyNav ({ active }) {
34
62
  activeTabId={active}
35
63
  onTabClick={() => {}}
36
64
  data-consultancy-nav
65
+ style={{ height: 'auto', flexShrink: 0 }}
37
66
  />
38
67
  )
39
68
  }
@@ -0,0 +1,172 @@
1
+ import React, { useMemo } from 'react'
2
+ import { Icon, List, Page, Tags, Text, View, useLocale } from '@ossy/design-system'
3
+ import { AsyncStatus, useSdk } from '@ossy/sdk-react'
4
+ import { resourceIdOf } from '@ossy/calendar/holiday-locale'
5
+ import {
6
+ ListResources,
7
+ ListPanelLayout,
8
+ ResourcePanel,
9
+ listPanelPageProps,
10
+ useSelectedResourceId,
11
+ } from '@ossy/resources'
12
+ import { ConsultancyNav } from './ConsultancyNav.jsx'
13
+ import { CreateConsultancyButton } from './CreateConsultancyButton.jsx'
14
+ import { Definition } from './Definition.js'
15
+ import { location } from './locations.js'
16
+ import { ConsultancySchema } from './schema-ids.js'
17
+
18
+ function contentOf (resource) {
19
+ return resource?.content && typeof resource.content === 'object' ? resource.content : {}
20
+ }
21
+
22
+ function parseDay (value) {
23
+ if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}/.test(value)) {
24
+ const [year, month, day] = value.slice(0, 10).split('-').map(Number)
25
+ if (year && month && day) return new Date(year, month - 1, day)
26
+ }
27
+ const date = new Date(value)
28
+ return Number.isNaN(date.getTime()) ? null : date
29
+ }
30
+
31
+ function formatDay (value, language) {
32
+ const date = parseDay(value)
33
+ if (!date) return ''
34
+ const locale = language === 'sv' ? 'sv-SE' : 'en'
35
+ return new Intl.DateTimeFormat(locale, { dateStyle: 'medium' }).format(date)
36
+ }
37
+
38
+ function vacationRange (resource, language) {
39
+ const content = contentOf(resource)
40
+ const start = formatDay(content.start, language)
41
+ const end = formatDay(content.end, language)
42
+ if (start && end && start !== end) return `${start} – ${end}`
43
+ return start || end || ''
44
+ }
45
+
46
+ function recordLabel (resource, language) {
47
+ if (resource?.type === ConsultancySchema.vacation) {
48
+ const range = vacationRange(resource, language)
49
+ if (range) return range
50
+ }
51
+ const content = contentOf(resource)
52
+ const name = resource?.name || content.name || content.title || content.clientName
53
+ if (typeof name === 'string' && name.trim()) return name.trim()
54
+ return resource?.id || ''
55
+ }
56
+
57
+ function recordMeta (resource, byId, language) {
58
+ const content = contentOf(resource)
59
+ if (resource?.type === ConsultancySchema.vacation) {
60
+ const employeeId = resourceIdOf(content.employeeId)
61
+ const employee = employeeId ? byId.get(employeeId) : null
62
+ return employee ? recordLabel(employee, language) : ''
63
+ }
64
+ const value = content.email || content.clientName || content.status
65
+ return typeof value === 'string' && value.trim() ? value.trim() : ''
66
+ }
67
+
68
+ /**
69
+ * Storage-style list of one consultancy schema, with the resource panel beside it.
70
+ */
71
+ export function ConsultancyRecordList ({ schemaId, icon, listHeader, emptyText }) {
72
+ const sdk = useSdk()
73
+ const { language } = useLocale()
74
+ const { selectedResourceId, setSelectedResourceId, clearSelectedResourceId } = useSelectedResourceId()
75
+ const { data: resources = [], status } = sdk.read(ListResources, { location })
76
+
77
+ const byId = useMemo(() => {
78
+ const list = Array.isArray(resources) ? resources : []
79
+ const map = new Map()
80
+ for (const resource of list) {
81
+ if (resource?.id) map.set(resource.id, resource)
82
+ const contentId = contentOf(resource).id
83
+ if (typeof contentId === 'string' && contentId.trim()) map.set(contentId.trim(), resource)
84
+ }
85
+ return map
86
+ }, [resources])
87
+
88
+ const rows = useMemo(() => {
89
+ const list = Array.isArray(resources) ? resources : []
90
+ return list
91
+ .filter((resource) => resource.type === schemaId)
92
+ .sort((a, b) => recordLabel(a, language).localeCompare(recordLabel(b, language)))
93
+ }, [resources, schemaId, language])
94
+
95
+ const loading = status === AsyncStatus.Loading || status === AsyncStatus.NotInitialized
96
+
97
+ return (
98
+ <ListPanelLayout
99
+ data-consultancy-records={schemaId}
100
+ listHeader={listHeader}
101
+ style={{ flex: '1 1 auto', minHeight: 0 }}
102
+ list={loading ? (
103
+ <View inset="m">
104
+ <Text color="secondary" text="consultancy.records.loading" />
105
+ </View>
106
+ ) : rows.length === 0 ? (
107
+ <View inset="m">
108
+ <Text color="secondary" text={emptyText} />
109
+ </View>
110
+ ) : (
111
+ <List>
112
+ {rows.map((resource) => {
113
+ const label = recordLabel(resource, language)
114
+ const meta = recordMeta(resource, byId, language)
115
+ return (
116
+ <List.Item
117
+ key={resource.id}
118
+ selectable
119
+ selected={resource.id === selectedResourceId}
120
+ onClick={() => setSelectedResourceId(resource.id)}
121
+ data-resource-name={label || undefined}
122
+ leading={(
123
+ <Icon size="s" name={icon || 'file'} style={{ fill: 'hsl(0, 0%, 80%)' }} />
124
+ )}
125
+ meta={meta ? <Text variant="small">{meta}</Text> : null}
126
+ >
127
+ {label}
128
+ </List.Item>
129
+ )
130
+ })}
131
+ </List>
132
+ )}
133
+ panel={selectedResourceId
134
+ ? <ResourcePanel width="100%" resourceId={selectedResourceId} onClose={clearSelectedResourceId} />
135
+ : null}
136
+ />
137
+ )
138
+ }
139
+
140
+ export function ConsultancyRecordPage ({
141
+ active,
142
+ title,
143
+ description,
144
+ schemaId,
145
+ icon,
146
+ listHeader,
147
+ emptyText,
148
+ }) {
149
+ const statusTags = (Definition.status ?? [])
150
+ .map((status) => ({ beta: 'Beta', 'coming-soon': 'Coming Soon' }[status]))
151
+ .filter(Boolean)
152
+
153
+ return (
154
+ <Page
155
+ {...listPanelPageProps}
156
+ title={title}
157
+ near={statusTags.length > 0 ? <Tags tags={statusTags} size="s" /> : undefined}
158
+ description={description}
159
+ far={<CreateConsultancyButton />}
160
+ >
161
+ <View gap="m" style={{ flex: '1 1 auto', height: '100%', minHeight: 0, display: 'flex', flexDirection: 'column' }}>
162
+ <ConsultancyNav active={active} />
163
+ <ConsultancyRecordList
164
+ schemaId={schemaId}
165
+ icon={icon}
166
+ listHeader={listHeader}
167
+ emptyText={emptyText}
168
+ />
169
+ </View>
170
+ </Page>
171
+ )
172
+ }
@@ -1,7 +1,22 @@
1
1
  import React from 'react'
2
- import { Button, useLocale } from '@ossy/design-system'
2
+ import { Button, ContextMenu, Dropdown, View, useLocale } from '@ossy/design-system'
3
3
  import { useRouter } from '@ossy/router-react'
4
4
  import { location } from './locations.js'
5
+ import companyBasicInfoSchema from './company-basic-info.schema.js'
6
+ import employeeSchema from './employee.schema.js'
7
+ import contractSchema from './contract.schema.js'
8
+ import vacationSchema from './vacation.schema.js'
9
+ import opportunitySchema from './opportunity.schema.js'
10
+ import proposalSchema from './proposal.schema.js'
11
+
12
+ const ADD_TYPES = [
13
+ { schema: companyBasicInfoSchema, label: 'consultancy.add.company' },
14
+ { schema: employeeSchema, label: 'consultancy.add.employee' },
15
+ { schema: contractSchema, label: 'consultancy.add.contract' },
16
+ { schema: opportunitySchema, label: 'consultancy.add.opportunity' },
17
+ { schema: proposalSchema, label: 'consultancy.add.proposal' },
18
+ { schema: vacationSchema, label: 'consultancy.add.vacation' },
19
+ ]
5
20
 
6
21
  function currentReturnTo (href) {
7
22
  const raw = typeof href === 'string' && href
@@ -21,26 +36,59 @@ function currentReturnTo (href) {
21
36
  }
22
37
  }
23
38
 
39
+ function createHref (router, schemaId) {
40
+ const params = new URLSearchParams({ location, category: 'Consultancy' })
41
+ if (schemaId) params.set('schemaId', schemaId)
42
+ const returnTo = currentReturnTo(router.href)
43
+ if (returnTo) params.set('returnTo', returnTo)
44
+ return router.getHref(`@create-document?${params.toString()}`)
45
+ }
46
+
24
47
  /**
25
- * Add CTA that opens the generic create-document form for consultancy schemas.
48
+ * Add CTA for consultancy schemas.
49
+ * Without `schemaId`, opens a dropdown of document types instead of the type-picker page.
50
+ * With `schemaId`, links straight to that type's create form.
26
51
  * @param {{ schemaId?: string }} [props]
27
52
  */
28
53
  export function CreateConsultancyButton ({ schemaId, ...props }) {
29
54
  const { t } = useLocale()
30
55
  const router = useRouter()
31
- const params = new URLSearchParams({ location, category: 'Consultancy' })
32
- if (schemaId) params.set('schemaId', schemaId)
33
- const returnTo = currentReturnTo(router.href)
34
- if (returnTo) params.set('returnTo', returnTo)
56
+
57
+ if (schemaId) {
58
+ return (
59
+ <Button
60
+ variant="cta"
61
+ prefix="add"
62
+ href={createHref(router, schemaId)}
63
+ {...props}
64
+ >
65
+ {t('design-system.add')}
66
+ </Button>
67
+ )
68
+ }
35
69
 
36
70
  return (
37
- <Button
38
- variant="cta"
39
- prefix="add"
40
- href={router.getHref(`@create-document?${params.toString()}`)}
41
- {...props}
71
+ <Dropdown
72
+ trigger={(
73
+ <Button variant="cta" prefix="add" {...props}>
74
+ {t('design-system.add')}
75
+ </Button>
76
+ )}
42
77
  >
43
- {t('design-system.add')}
44
- </Button>
78
+ <View inset="xs" surface="primary" roundness="s">
79
+ <ContextMenu roundness="s" surface="primary">
80
+ {ADD_TYPES.map(({ schema, label }) => (
81
+ <ContextMenu.Item
82
+ key={schema.id}
83
+ prefix={schema.icon || 'add'}
84
+ href={createHref(router, schema.id)}
85
+ data-schema-id={schema.id}
86
+ >
87
+ {t(label)}
88
+ </ContextMenu.Item>
89
+ ))}
90
+ </ContextMenu>
91
+ </View>
92
+ </Dropdown>
45
93
  )
46
94
  }