|
1 | 1 | import { WorkspaceResponse } from '@/types/common'; |
2 | 2 |
|
3 | | -export const getWorkspaceLabels = (workspace?: WorkspaceResponse, shouldCapitalize?: boolean) => { |
4 | | - const capitalize = (str?: string) => (str ? str.charAt(0).toUpperCase() + str.slice(1) : str); |
| 3 | +type WorkspaceLabels = { |
| 4 | + individualTerm: string; |
| 5 | + individualTermPlural: string; |
| 6 | + groupTerm: string; |
| 7 | + groupTermPlural: string; |
| 8 | +}; |
| 9 | + |
| 10 | +export const getWorkspaceLabels = (workspace?: WorkspaceResponse, shouldCapitalize?: boolean): WorkspaceLabels => { |
| 11 | + const capitalize = (str?: string): string => (str ? str.charAt(0).toUpperCase() + str.slice(1) : ''); |
| 12 | + const deCapitalize = (str?: string): string => (str ? str.charAt(0).toLowerCase() + str.slice(1) : ''); |
5 | 13 | const labels = shouldCapitalize |
6 | 14 | ? { |
7 | | - individualTerm: workspace?.label?.individualTerm ? capitalize(workspace.label.individualTerm) : 'Client', |
8 | | - individualTermPlural: workspace?.label?.individualTermPlural |
9 | | - ? capitalize(workspace.label.individualTermPlural) |
| 15 | + individualTerm: workspace?.labels?.individualTerm ? capitalize(workspace.labels.individualTerm) : 'Client', |
| 16 | + individualTermPlural: workspace?.labels?.individualTermPlural |
| 17 | + ? capitalize(workspace.labels.individualTermPlural) |
10 | 18 | : 'Clients', |
11 | | - groupTerm: workspace?.label?.groupTerm ? capitalize(workspace.label.groupTerm) : 'Company', |
12 | | - groupTermPlural: workspace?.label?.groupTermPlural ? capitalize(workspace.label.groupTermPlural) : 'Companies', |
| 19 | + groupTerm: workspace?.labels?.groupTerm ? capitalize(workspace.labels.groupTerm) : 'Company', |
| 20 | + groupTermPlural: workspace?.labels?.groupTermPlural ? capitalize(workspace.labels.groupTermPlural) : 'Companies', |
13 | 21 | } |
14 | 22 | : { |
15 | | - individualTerm: workspace?.label?.individualTerm ? workspace.label.individualTerm : 'client', |
16 | | - individualTermPlural: workspace?.label?.individualTermPlural ? workspace.label.individualTermPlural : 'clients', |
17 | | - groupTerm: workspace?.label?.groupTerm ? workspace.label.groupTerm : 'company', |
18 | | - groupTermPlural: workspace?.label?.groupTermPlural ? workspace.label.groupTermPlural : 'companies', |
19 | | - }; //clean this when we are making workspace's label field non-optional. |
| 23 | + individualTerm: workspace?.labels?.individualTerm ? deCapitalize(workspace.labels.individualTerm) : 'client', |
| 24 | + individualTermPlural: workspace?.labels?.individualTermPlural |
| 25 | + ? deCapitalize(workspace.labels.individualTermPlural) |
| 26 | + : 'clients', |
| 27 | + groupTerm: workspace?.labels?.groupTerm ? deCapitalize(workspace.labels.groupTerm) : 'company', |
| 28 | + groupTermPlural: workspace?.labels?.groupTermPlural ? deCapitalize(workspace.labels.groupTermPlural) : 'companies', |
| 29 | + }; |
20 | 30 |
|
21 | 31 | return labels; |
22 | 32 | }; |
0 commit comments