fix(front) : masque les onglets vides en consultation des 4 repertoires (ERP-193)
This commit is contained in:
@@ -10,6 +10,7 @@ const {
|
||||
canEditProvider,
|
||||
categoryOptionsOf,
|
||||
contactOptionsOf,
|
||||
hasAccountingData,
|
||||
iriOf,
|
||||
irisOf,
|
||||
mapAccountingDraft,
|
||||
@@ -17,6 +18,7 @@ const {
|
||||
mapContactToDraft,
|
||||
mapRibToDraft,
|
||||
paymentTypeCodeOf,
|
||||
providerConsultationVisibleTabs,
|
||||
referentialOptionOf,
|
||||
showArchiveAction,
|
||||
showRestoreAction,
|
||||
@@ -165,3 +167,48 @@ describe('providerDetail helpers', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('hasAccountingData (prestataire)', () => {
|
||||
it('faux sans champ comptable ni RIB', () => {
|
||||
expect(hasAccountingData({ '@id': '/api/providers/1', id: 1 })).toBe(false)
|
||||
})
|
||||
|
||||
it('vrai avec un champ comptable ou un RIB', () => {
|
||||
expect(hasAccountingData({ '@id': '/api/providers/1', id: 1, siren: '123456789' })).toBe(true)
|
||||
expect(hasAccountingData({
|
||||
'@id': '/api/providers/1', id: 1,
|
||||
ribs: [{ '@id': '/api/provider_ribs/1', id: 1, iban: 'FR76...' }],
|
||||
})).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('providerConsultationVisibleTabs', () => {
|
||||
it('retourne [] tant que le prestataire n\'est pas charge', () => {
|
||||
expect(providerConsultationVisibleTabs(null, { canAccountingView: true })).toEqual([])
|
||||
})
|
||||
|
||||
it('masque les coquilles (reports/exchanges) et les onglets vides', () => {
|
||||
expect(providerConsultationVisibleTabs(
|
||||
{ '@id': '/api/providers/1', id: 1, companyName: 'ACME' },
|
||||
{ canAccountingView: true },
|
||||
)).toEqual([])
|
||||
})
|
||||
|
||||
it('affiche contacts/address/accounting dans l\'ordre (pas d\'onglet information)', () => {
|
||||
const provider = {
|
||||
'@id': '/api/providers/1', id: 1,
|
||||
contacts: [{ '@id': '/api/provider_contacts/1', id: 1 }],
|
||||
addresses: [{ '@id': '/api/provider_addresses/1', id: 1 }],
|
||||
siren: '123456789',
|
||||
}
|
||||
expect(providerConsultationVisibleTabs(provider, { canAccountingView: true }))
|
||||
.toEqual(['contacts', 'address', 'accounting'])
|
||||
})
|
||||
|
||||
it('masque Comptabilite sans le droit accounting.view', () => {
|
||||
expect(providerConsultationVisibleTabs(
|
||||
{ '@id': '/api/providers/1', id: 1, siren: '123456789' },
|
||||
{ canAccountingView: false },
|
||||
)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -224,6 +224,58 @@ export function paymentTypeCodeOf(relation: Relation): string | null {
|
||||
return (relation.code as string | undefined) ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrai si une valeur scalaire porte une donnee affichable (non null/undefined,
|
||||
* et non chaine vide apres trim). Sert au predicat « onglet vide » ci-dessous.
|
||||
*/
|
||||
function hasValue(value: unknown): boolean {
|
||||
if (value === null || value === undefined) {
|
||||
return false
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return value.trim() !== ''
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrai si l'onglet Comptabilite porte au moins un champ comptable OU un RIB.
|
||||
* (Le gating permission `accounting.view` reste applique en amont par l'appelant.)
|
||||
*/
|
||||
export function hasAccountingData(provider: ProviderDetail): boolean {
|
||||
const draft = mapAccountingDraft(provider)
|
||||
const hasField = Object.values(draft).some(hasValue)
|
||||
const hasRib = (provider.ribs ?? []).length > 0
|
||||
return hasField || hasRib
|
||||
}
|
||||
|
||||
/**
|
||||
* Onglets visibles en consultation (ERP-193, retour metier) : on masque les
|
||||
* coquilles non implementees (Rapports / Echanges) ET tout onglet de donnees
|
||||
* vide. Le prestataire n'a pas d'onglet Information (bloc principal au-dessus
|
||||
* des onglets). Ordre : Contacts · Adresse · Comptabilite. Retourne `[]` tant
|
||||
* que le prestataire n'est pas charge.
|
||||
*/
|
||||
export function providerConsultationVisibleTabs(
|
||||
provider: ProviderDetail | null | undefined,
|
||||
options: { canAccountingView: boolean },
|
||||
): string[] {
|
||||
if (!provider) {
|
||||
return []
|
||||
}
|
||||
const visible: string[] = []
|
||||
if ((provider.contacts ?? []).length > 0) {
|
||||
visible.push('contacts')
|
||||
}
|
||||
if ((provider.addresses ?? []).length > 0) {
|
||||
visible.push('address')
|
||||
}
|
||||
if (options.canAccountingView && hasAccountingData(provider)) {
|
||||
visible.push('accounting')
|
||||
}
|
||||
return visible
|
||||
}
|
||||
|
||||
/**
|
||||
* Bouton « Modifier » : visible si l'utilisateur peut editer au moins un onglet —
|
||||
* `manage` (onglets metier) OU `accounting.manage` (le role Compta doit pouvoir
|
||||
|
||||
Reference in New Issue
Block a user