-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web-office): add general information dashboard
ref: MANAGER-16832 Signed-off-by: Guillaume Hyenne <[email protected]>
- Loading branch information
Showing
33 changed files
with
862 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...ges/manager/apps/web-office/public/translations/dashboard/consumption/Messages_fr_FR.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ger/apps/web-office/public/translations/dashboard/general-information/Messages_fr_FR.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dashboard_modal_update_headline": "Changer le nom", | ||
"dashboard_modal_update_description": "Veuilliez saisir le nouveau nom que vous souhaitez donner à votre service.", | ||
"dashboard_modal_update_input_label": "Nouveau nom" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/manager/apps/web-office/src/api/_mock_/parentTenant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { UserStateEnum } from '../api.type'; | ||
import { ParentTenantType } from '../parentTenant'; | ||
|
||
export const parentTenantMock: ParentTenantType = { | ||
address: '123 Main Street', | ||
city: 'Springfield', | ||
creationDate: '2023-05-15', | ||
displayName: 'John Doe', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
phone: '+1234567890', | ||
serviceName: 'office5678.o365.ovh.com-1234', | ||
serviceType: 'prepaid', | ||
status: UserStateEnum.OK, | ||
zipCode: '12345', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,18 @@ export const usersMock: UserNativeType[] = [ | |
firstName: 'test', | ||
isVirtual: false, | ||
lastName: 'test', | ||
licences: [LicenseEnum.OFFICE_BUSINESS], | ||
licences: [LicenseEnum.OFFICE_PRO_PLUS], | ||
status: UserStateEnum.OK, | ||
taskPendingId: 0, | ||
usageLocation: 'fr', | ||
}, | ||
{ | ||
activationEmail: '[email protected]', | ||
deleteAtExpiration: false, | ||
firstName: 'test', | ||
isVirtual: false, | ||
lastName: 'test', | ||
licences: [LicenseEnum.OFFICE_PRO_PLUS], | ||
status: UserStateEnum.OK, | ||
taskPendingId: 0, | ||
usageLocation: 'fr', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/manager/apps/web-office/src/api/parentTenant/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { v6 } from '@ovh-ux/manager-core-api'; | ||
import { getApiPath } from '../utils/apiPath'; | ||
import { ParentTenantType } from './type'; | ||
|
||
export const getParentTenant = async ( | ||
serviceName: string, | ||
): Promise<ParentTenantType> => { | ||
const { data } = await v6.get<ParentTenantType>( | ||
`${getApiPath(serviceName)}parentTenant`, | ||
); | ||
return data; | ||
}; | ||
|
||
export const putParentTenant = async ( | ||
serviceName: string, | ||
parentTenantData: Partial<ParentTenantType>, | ||
): Promise<ParentTenantType> => { | ||
const { data } = await v6.put<ParentTenantType>( | ||
`${getApiPath(serviceName)}parentTenant`, | ||
parentTenantData, | ||
); | ||
return data; | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/manager/apps/web-office/src/api/parentTenant/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './api'; | ||
export * from './key'; | ||
export * from './type'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const getOfficeParentTenantQueryKey = (serviceName: string) => [ | ||
'get', | ||
'license', | ||
'officePrepaid', | ||
serviceName, | ||
'parentTenant', | ||
]; |
15 changes: 15 additions & 0 deletions
15
packages/manager/apps/web-office/src/api/parentTenant/type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { UserStateEnum } from '../api.type'; | ||
|
||
export type ParentTenantType = { | ||
address: string; | ||
city: string; | ||
creationDate: string; | ||
displayName: string; | ||
firstName: string; | ||
lastName: string; | ||
phone: string; | ||
serviceName: string; | ||
serviceType: string; | ||
status: UserStateEnum; | ||
zipCode: string; | ||
}; |
59 changes: 59 additions & 0 deletions
59
.../apps/web-office/src/components/layout-helpers/Dashboard/OfficeServiceState.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { ODS_BADGE_COLOR, ODS_BADGE_SIZE } from '@ovhcloud/ods-components'; | ||
import { OdsBadge } from '@ovhcloud/ods-components/react'; | ||
import { StateEnum } from '@/api/serviceInfos'; | ||
|
||
export type OfficeStateProps = { | ||
size?: ODS_BADGE_SIZE; | ||
state: StateEnum; | ||
} & Record<string, string>; | ||
|
||
export const OfficeServiceState = ({ state, ...props }: OfficeStateProps) => { | ||
const { t } = useTranslation('common'); | ||
|
||
const { size, ...otherProps } = props; | ||
|
||
let label = ''; | ||
let color: ODS_BADGE_COLOR; | ||
|
||
switch (state) { | ||
case StateEnum.Ok: | ||
label = t('state_ok'); | ||
color = ODS_BADGE_COLOR.success; | ||
break; | ||
case StateEnum.AutoRenewInProgress: | ||
label = t('state_autorenewInProgress'); | ||
color = ODS_BADGE_COLOR.information; | ||
break; | ||
case StateEnum.Expired: | ||
label = t('state_expired'); | ||
color = ODS_BADGE_COLOR.critical; | ||
break; | ||
case StateEnum.InCreation: | ||
label = t('state_inCreation'); | ||
color = ODS_BADGE_COLOR.information; | ||
break; | ||
case StateEnum.UnPaid: | ||
label = t('state_unPaid'); | ||
color = ODS_BADGE_COLOR.critical; | ||
break; | ||
case StateEnum.PendingDebt: | ||
label = t('state_pendingDebt'); | ||
color = ODS_BADGE_COLOR.information; | ||
break; | ||
default: | ||
label = state; | ||
color = ODS_BADGE_COLOR.neutral; | ||
break; | ||
} | ||
|
||
return ( | ||
<OdsBadge | ||
data-testid="badge-status" | ||
size={size || ODS_BADGE_SIZE.md} | ||
color={color} | ||
label={label} | ||
{...otherProps} | ||
/> | ||
); | ||
}; |
69 changes: 69 additions & 0 deletions
69
...ce/src/components/layout-helpers/Dashboard/__test__/OfficeServiceState.component.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import { describe, expect } from 'vitest'; | ||
import { ODS_BADGE_COLOR } from '@ovhcloud/ods-components'; | ||
import { render } from '@/utils/test.provider'; | ||
import { OfficeServiceState } from '../OfficeServiceState.component'; | ||
import commonTranslation from '@/public/translations/common/Messages_fr_FR.json'; | ||
|
||
describe('OfficeServiceState component', () => { | ||
it('Badge for ok status', async () => { | ||
const { getByTestId } = render(<OfficeServiceState state={'ok'} />); | ||
const badge = getByTestId('badge-status'); | ||
|
||
expect(badge).toHaveAttribute('label', commonTranslation.state_ok); | ||
|
||
expect(badge).toHaveAttribute('color', ODS_BADGE_COLOR.success); | ||
}); | ||
|
||
it('Badge for autorenewInProgress status', () => { | ||
const { getByTestId } = render( | ||
<OfficeServiceState state={'autorenewInProgress'} />, | ||
); | ||
const badge = getByTestId('badge-status'); | ||
|
||
expect(badge).toHaveAttribute( | ||
'label', | ||
commonTranslation.state_autorenewInProgress, | ||
); | ||
|
||
expect(badge).toHaveAttribute('color', ODS_BADGE_COLOR.information); | ||
}); | ||
|
||
it('Badge for expired status', () => { | ||
const { getByTestId } = render(<OfficeServiceState state={'expired'} />); | ||
const badge = getByTestId('badge-status'); | ||
|
||
expect(badge).toHaveAttribute('label', commonTranslation.state_expired); | ||
|
||
expect(badge).toHaveAttribute('color', ODS_BADGE_COLOR.critical); | ||
}); | ||
|
||
it('Badge for inCreation status', () => { | ||
const { getByTestId } = render(<OfficeServiceState state={'inCreation'} />); | ||
const badge = getByTestId('badge-status'); | ||
|
||
expect(badge).toHaveAttribute('label', commonTranslation.state_inCreation); | ||
|
||
expect(badge).toHaveAttribute('color', ODS_BADGE_COLOR.information); | ||
}); | ||
|
||
it('Badge for unPaid status', () => { | ||
const { getByTestId } = render(<OfficeServiceState state={'unPaid'} />); | ||
const badge = getByTestId('badge-status'); | ||
|
||
expect(badge).toHaveAttribute('label', commonTranslation.state_unPaid); | ||
|
||
expect(badge).toHaveAttribute('color', ODS_BADGE_COLOR.critical); | ||
}); | ||
|
||
it('Badge for pendingDebt status', () => { | ||
const { getByTestId } = render( | ||
<OfficeServiceState state={'pendingDebt'} />, | ||
); | ||
const badge = getByTestId('badge-status'); | ||
|
||
expect(badge).toHaveAttribute('label', commonTranslation.state_pendingDebt); | ||
|
||
expect(badge).toHaveAttribute('color', ODS_BADGE_COLOR.information); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
packages/manager/apps/web-office/src/hooks/__test__/useOfficeParentTenant.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { vi, describe, expect } from 'vitest'; | ||
import '@testing-library/jest-dom'; | ||
import { renderHook, waitFor } from '@testing-library/react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { | ||
parentTenantMock, | ||
licensesMock, | ||
licensesPrepaidMock, | ||
} from '@/api/_mock_'; | ||
import { useOfficeParentTenant } from '@/hooks'; | ||
import { wrapper } from '@/utils/test.provider'; | ||
|
||
describe('useOfficeParentTenant', () => { | ||
it('should return the detail of parentTenant if prepaid', async () => { | ||
vi.mocked(useParams).mockReturnValue({ | ||
serviceName: licensesPrepaidMock[0], | ||
}); | ||
|
||
const { result } = renderHook(() => useOfficeParentTenant(), { | ||
wrapper, | ||
}); | ||
await waitFor(() => { | ||
expect(result.current.isSuccess).toBe(true); | ||
}); | ||
expect(result.current.data).toEqual(parentTenantMock); | ||
}); | ||
|
||
it('should return the detail of current license if payAsYouGo', async () => { | ||
vi.mocked(useParams).mockReturnValue({ | ||
serviceName: licensesMock[0].serviceName, | ||
}); | ||
const { result } = renderHook(() => useOfficeParentTenant(), { | ||
wrapper, | ||
}); | ||
await waitFor(() => { | ||
expect(result.current.isSuccess).toBe(true); | ||
}); | ||
expect(result.current.data).toEqual(licensesMock[0]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/manager/apps/web-office/src/hooks/useOfficeParentTenant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useOfficeServiceType } from './useOfficeServiceType'; | ||
import { | ||
getParentTenant, | ||
getOfficeParentTenantQueryKey, | ||
} from '@/api/parentTenant'; | ||
import { | ||
getOfficeLicenseDetailsQueryKey, | ||
getOfficeLicenseDetails, | ||
} from '@/api/license'; | ||
|
||
export const useOfficeParentTenant = () => { | ||
const { serviceName } = useParams(); | ||
const serviceType = useOfficeServiceType(serviceName); | ||
const isPrepaid = serviceType === 'prepaid'; | ||
|
||
return useQuery({ | ||
queryKey: [ | ||
isPrepaid | ||
? getOfficeParentTenantQueryKey(serviceName) | ||
: getOfficeLicenseDetailsQueryKey(serviceName), | ||
], | ||
queryFn: isPrepaid | ||
? () => getParentTenant(serviceName) | ||
: () => getOfficeLicenseDetails(serviceName), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.