-
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
20 changed files
with
259 additions
and
46 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
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
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`, | ||
); | ||
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 |
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
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
26 changes: 26 additions & 0 deletions
26
packages/manager/apps/web-office/src/hooks/officeParentTenant/getOfficeParentTenant.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,26 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useOfficeServiceType } from '../useOfficeServiceType'; | ||
import { getParentTenant } from '@/api/parentTenant/api'; | ||
import { | ||
getlicenseOfficeServiceQueryKey, | ||
getOfficeLicenseDetails, | ||
} from '@/api/license/api'; | ||
import { getOfficeParentTenantQueryKey } from '@/api/parentTenant/key'; | ||
|
||
export const getOfficeParentTenant = () => { | ||
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), | ||
}); | ||
}; |
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; | ||
}; |
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
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 { | ||
getOfficeParentTenant, | ||
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 { getOfficeParentTenantQueryKey } 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 } = getOfficeParentTenant(); | ||
|
||
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 | ||
? getOfficeParentTenantQueryKey(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} | ||
/> | ||
); | ||
} |
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.