-
Notifications
You must be signed in to change notification settings - Fork 98
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 update displayName for title on dashboard
ref:MANAGER-16189 Signed-off-by: stif59100 <[email protected]>
- Loading branch information
Showing
26 changed files
with
343 additions
and
45 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
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './license'; | ||
export * from './user'; | ||
export * from './parentTenant'; |
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
29 changes: 29 additions & 0 deletions
29
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,29 @@ | ||
import { v6 } from '@ovh-ux/manager-core-api'; | ||
import { getApiPath } from '../utils/apiPath'; | ||
import { ParentTenantType } from './type'; | ||
|
||
// GET | ||
export const getParentTenant = async ( | ||
serviceName: string, | ||
): Promise<ParentTenantType> => { | ||
const { data } = await v6.get<ParentTenantType>( | ||
`${getApiPath(serviceName)}parentTenant`, | ||
); | ||
console.log('parentTenant', data); | ||
return data; | ||
}; | ||
// POST | ||
|
||
// PUT | ||
export const updateParentTenant = async ( | ||
serviceName: string, | ||
parentTenantData: Partial<ParentTenantType>, | ||
): Promise<ParentTenantType> => { | ||
const { data } = await v6.put<ParentTenantType>( | ||
`${getApiPath(serviceName)}parentTenant`, | ||
parentTenantData, | ||
); | ||
return data; | ||
}; | ||
|
||
// DELETE |
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; | ||
}; |
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
12 changes: 12 additions & 0 deletions
12
packages/manager/apps/web-office/src/components/Breadcrumb/__test__/Breadcrumb.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,12 @@ | ||
import React from 'react'; | ||
import { describe, expect } from 'vitest'; | ||
import { render } from '@/utils/test.provider'; | ||
import Breadcrumb from '../Breadcrumb'; | ||
|
||
describe('Breadcrumb component', () => { | ||
it('should render', async () => { | ||
const { getByTestId } = render(<Breadcrumb />); | ||
const cmp = getByTestId('breadcrumb'); | ||
expect(cmp).toBeInTheDocument(); | ||
}); | ||
}); |
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
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
import { vi, describe, expect } from 'vitest'; | ||
import '@testing-library/jest-dom'; | ||
import { renderHook, waitFor } from '@testing-library/react'; | ||
import { parentTenantMock, licensesMock } from '@/api/_mock_'; | ||
import { useOfficeParentTenant } from '@/hooks'; | ||
import { wrapper } from '@/utils/test.provider'; | ||
|
||
const useParamsMock = vi.hoisted(() => ({ | ||
useParams: vi.fn(), | ||
})); | ||
|
||
vi.mock('react-router-dom', async (importActual) => { | ||
const actual = await importActual<typeof import('react-router-dom')>(); | ||
return { | ||
...actual, | ||
useParams: useParamsMock.useParams, | ||
}; | ||
}); | ||
|
||
describe('useOfficeParentTenant', () => { | ||
it('should return the detail of one parentTenant', async () => { | ||
useParamsMock.useParams.mockReturnValue({ | ||
serviceName: parentTenantMock.serviceName, | ||
}); | ||
const { result } = renderHook(() => useOfficeParentTenant(), { | ||
wrapper, | ||
}); | ||
await waitFor(() => { | ||
expect(result.current.isSuccess).toBe(true); | ||
Check failure on line 29 in packages/manager/apps/web-office/src/hooks/__test__/useOfficeParentTenant.spec.tsx GitHub Actions / testsrc/hooks/__test__/useOfficeParentTenant.spec.tsx > useOfficeParentTenant > should return the detail of one parentTenant
|
||
}); | ||
expect(result.current.data).toEqual(parentTenantMock); | ||
}); | ||
}); |
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
19 changes: 2 additions & 17 deletions
19
packages/manager/apps/web-office/src/hooks/useGenerateUrl.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 |
---|---|---|
@@ -1,32 +1,17 @@ | ||
import { useHref } from 'react-router-dom'; | ||
import { useOfficeLicenseDetail } from '@/hooks'; | ||
|
||
export const UseGenerateUrl = ( | ||
baseURL: string, | ||
type: 'path' | 'href' = 'path', | ||
params?: Record<string, string | number>, | ||
) => { | ||
const { data: serviceName } = useOfficeLicenseDetail(); | ||
|
||
const URL = baseURL.replace( | ||
':serviceName', | ||
(params?.serviceName as string) || '', | ||
); | ||
|
||
const queryParams = { | ||
...params, | ||
...(serviceName && { serviceNameDetail: serviceName }), | ||
}; | ||
|
||
const queryString = Object.entries(queryParams) | ||
.filter(([key]) => key !== 'serviceName') | ||
.map(([key, value]) => `${key}=${value}`) | ||
.join('&'); | ||
|
||
const fullURL = queryString ? `${URL}?${queryString}` : URL; | ||
|
||
if (type === 'href') { | ||
return useHref(fullURL); | ||
return useHref(URL); | ||
} | ||
return fullURL; | ||
return URL; | ||
}; |
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 { | ||
getlicenseOfficeServiceQueryKey, | ||
getOfficeLicenseDetails, | ||
} from '@/api/license'; | ||
|
||
export const useOfficeParentTenant = () => { | ||
const { serviceName } = useParams(); | ||
const serviceType = useOfficeServiceType(serviceName); | ||
const isPrepaid = serviceType === 'prepaid'; | ||
|
||
return useQuery({ | ||
queryKey: [ | ||
isPrepaid | ||
? getOfficeParentTenantQueryKey(serviceName) | ||
: getlicenseOfficeServiceQueryKey(serviceName), | ||
], | ||
queryFn: isPrepaid | ||
? () => getParentTenant(serviceName) | ||
: () => getOfficeLicenseDetails(serviceName), | ||
}); | ||
}; |
65 changes: 65 additions & 0 deletions
65
...nager/apps/web-office/src/pages/dashboard/components/UpdateDisplayNameModal.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,65 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { UpdateNameModal } from '@ovh-ux/manager-react-components'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { | ||
useOfficeParentTenant, | ||
UseGenerateUrl, | ||
useOfficeServiceType, | ||
} from '@/hooks'; | ||
import queryClient from '@/queryClient'; | ||
import { ParentTenantType } from '@/api/parentTenant/type'; | ||
import { updateOfficeLicenseDetails } from '@/api/license/api'; | ||
import { updateParentTenant } from '@/api/parentTenant/api'; | ||
import { LicenseType } from '@/api/license/type'; | ||
import { useOfficeParentTenantQueryKey } from '@/api/parentTenant/key'; | ||
import { getOfficeLicenseDetailsQueryKey } from '@/api/license/key'; | ||
|
||
export default function UpdateDisplayNameModal() { | ||
const navigate = useNavigate(); | ||
const { t } = useTranslation('dashboard'); | ||
const { serviceName } = useParams(); | ||
const serviceType = useOfficeServiceType(serviceName); | ||
const isPrepaid = serviceType === 'prepaid'; | ||
const { data: getData, refetch } = useOfficeParentTenant(); | ||
|
||
const goBackUrl = UseGenerateUrl('..', 'path'); | ||
const closeModal = () => { | ||
navigate(goBackUrl, { replace: true }); | ||
}; | ||
const { mutate: editName, isPending } = useMutation({ | ||
mutationFn: isPrepaid | ||
? (parentTenantData: Partial<ParentTenantType>) => | ||
updateParentTenant(serviceName, parentTenantData) | ||
: (licenseData: Partial<LicenseType>) => | ||
updateOfficeLicenseDetails(serviceName, licenseData), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: isPrepaid | ||
? useOfficeParentTenantQueryKey(serviceName) | ||
: getOfficeLicenseDetailsQueryKey(serviceName), | ||
}); | ||
closeModal(); | ||
refetch(); | ||
}, | ||
}); | ||
const handleSaveClick = (displayName: string) => { | ||
editName({ displayName }); | ||
}; | ||
|
||
return ( | ||
<UpdateNameModal | ||
isOpen={true} | ||
isLoading={isPending} | ||
closeModal={closeModal} | ||
headline={t('microsoft_office_modal_update_headline')} | ||
description={t('microsoft_office_modal_update_description')} | ||
inputLabel={t('microsoft_office_modal_update_input_label')} | ||
defaultValue={getData?.displayName} | ||
confirmButtonLabel={t('microsoft_office_modal_update_confirm')} | ||
cancelButtonLabel={t('microsoft_office_modal_update_cancel')} | ||
updateDisplayName={handleSaveClick} | ||
/> | ||
); | ||
} |
Oops, something went wrong.