-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(container): added an invitation modal to accept contract #14041
Open
JacquesLarique
wants to merge
10
commits into
master
Choose a base branch
from
feat/MANAGER-14722
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
77403c5
feat(shell): add method to notify container a modal action is done
ef2796b
feat(container): added an invitation modal to accept contract
46afc29
feat(container): add agreements update modal tests
25e78fa
feat(container): added aggreements modal and reviewed modals display
a3479a6
feat(container): added aggreements modal and reviewed modals display
87b4755
feat(container): added aggreements modal and reviewed modals display
bd620ea
feat(container): remove unnecessary comment
74ed2b2
feat(container): fixed typo in agreements update modal redirection url
c774dc1
feat(container): fixed agreements update modal display management
aa06630
feat(container): fixed agreements update modal tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { fetchIcebergV6, FilterComparator } from "@ovh-ux/manager-core-api"; | ||
|
||
const fetchAgreementsUpdates = async () => { | ||
const { data } = await fetchIcebergV6({ | ||
route: '/me/agreements', | ||
filters: [{ key: 'agreed', comparator: FilterComparator.IsIn, value: ['todo', 'ko'] }], | ||
}); | ||
return data; | ||
}; | ||
|
||
export default fetchAgreementsUpdates; |
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 { fetchIcebergV2 } from "@ovh-ux/manager-core-api"; | ||
|
||
type IamResource = { | ||
id: string; | ||
urn: string; | ||
name: string; | ||
displayName: string; | ||
type: string; | ||
owner: string; | ||
}; | ||
|
||
export const fetchAccountUrn = async (): Promise<string> => { | ||
const { data } = await fetchIcebergV2<IamResource>({ | ||
route: '/iam/resource?resourceType=account', | ||
}); | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a note to say why it s commented |
||
const { data } = await v2.get( | ||
'/iam/resource?resourceType=account', | ||
{ adapter: 'fetch',fetchOptions: { priority: 'low' } }, | ||
); | ||
*/ | ||
return data[0]?.urn; | ||
}; |
File renamed without changes
90 changes: 90 additions & 0 deletions
90
...r/apps/container/src/components/AgreementsUpdateModal/AgreementsUpdateModal.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,90 @@ | ||
import React, { useContext, useEffect } from 'react'; | ||
import useAgreementsUpdate from '@/hooks/agreements/useAgreementsUpdate'; | ||
import { ODS_THEME_COLOR_HUE, ODS_THEME_COLOR_INTENT, ODS_THEME_TYPOGRAPHY_SIZE } from '@ovhcloud/ods-common-theming'; | ||
import { OsdsButton, OsdsModal, OsdsText } from '@ovhcloud/ods-components/react'; | ||
import { ODS_BUTTON_SIZE, ODS_BUTTON_VARIANT, ODS_TEXT_LEVEL } from '@ovhcloud/ods-components'; | ||
import { useTranslation } from 'react-i18next'; | ||
import ApplicationContext from '@/context'; | ||
import ovhCloudLogo from '@/assets/images/logo-ovhcloud.png'; | ||
import { useAuthorizationIam } from '@ovh-ux/manager-react-components/src/hooks/iam'; | ||
import useAccountUrn from '@/hooks/accountUrn/useAccountUrn'; | ||
import { ModalTypes } from '@/context/modals/modals.context'; | ||
import { useModals } from '@/context/modals'; | ||
|
||
export default function AgreementsUpdateModal () { | ||
const { shell } = useContext(ApplicationContext); | ||
const region: string = shell | ||
.getPlugin('environment') | ||
.getEnvironment() | ||
.getRegion(); | ||
const navigation = shell.getPlugin('navigation'); | ||
const { current } = useModals(); | ||
const myContractsLink = navigation.getURL( | ||
'dedicated', | ||
'#/billing/autoRenew/agreements', | ||
); | ||
const { t } = useTranslation('agreements-update-modal'); | ||
const { data: urn } = useAccountUrn({ enabled: region !== 'US' && current === ModalTypes.agreements && window.location.href !== myContractsLink }); | ||
const { isAuthorized: canUserAcceptAgreements } = useAuthorizationIam(['account:apiovh:me/agreements/accept'], urn); | ||
const { data: agreements } = useAgreementsUpdate({ enabled: canUserAcceptAgreements }); | ||
const goToContractPage = () => { | ||
navigation.navigateTo('dedicated', `#/billing/autoRenew/agreements`); | ||
}; | ||
|
||
useEffect(() => { | ||
if (canUserAcceptAgreements && !agreements?.length && current === ModalTypes.agreements) { | ||
shell.getPlugin('ux').notifyModalActionDone(); | ||
} | ||
}, [canUserAcceptAgreements, agreements, current]); | ||
|
||
return agreements?.length ? ( | ||
<> | ||
<OsdsModal | ||
dismissible={false} | ||
className="text-center" | ||
color={ODS_THEME_COLOR_INTENT.info} | ||
data-testid="agreements-update-modal" | ||
> | ||
<div className="w-full flex justify-center items-center mb-6"> | ||
<img | ||
src={ovhCloudLogo} alt="ovh-cloud-logo" | ||
height={40} | ||
/> | ||
</div> | ||
<OsdsText | ||
level={ODS_TEXT_LEVEL.heading} | ||
color={ODS_THEME_COLOR_INTENT.primary} | ||
size={ODS_THEME_TYPOGRAPHY_SIZE._400} | ||
hue={ODS_THEME_COLOR_HUE._800} | ||
> | ||
{t('agreements_update_modal_title')} | ||
</OsdsText> | ||
<OsdsText | ||
level={ODS_TEXT_LEVEL.body} | ||
color={ODS_THEME_COLOR_INTENT.primary} | ||
size={ODS_THEME_TYPOGRAPHY_SIZE._400} | ||
hue={ODS_THEME_COLOR_HUE._800} | ||
> | ||
<p | ||
className="mt-6" | ||
dangerouslySetInnerHTML={{ | ||
__html: t('agreements_update_modal_description', { | ||
link: myContractsLink, | ||
}), | ||
}} | ||
></p> | ||
</OsdsText> | ||
|
||
<OsdsButton | ||
onClick={goToContractPage} | ||
slot="actions" | ||
color={ODS_THEME_COLOR_INTENT.primary} | ||
variant={ODS_BUTTON_VARIANT.flat} | ||
size={ODS_BUTTON_SIZE.sm} | ||
> | ||
{t('agreements_update_modal_action')} | ||
</OsdsButton> | ||
</OsdsModal> | ||
</> | ||
) : null; | ||
} |
91 changes: 91 additions & 0 deletions
91
...anager/apps/container/src/components/AgreementsUpdateModal/AgreementsUpdateModal.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,91 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { render } from '@testing-library/react'; | ||
import { vi } from 'vitest'; | ||
import { | ||
ShellContext, | ||
ShellContextType, | ||
} from '@ovh-ux/manager-react-shell-client'; | ||
import AgreementsUpdateModal from '@/components/AgreementsUpdateModal/AgreementsUpdateModal.component'; | ||
|
||
const mocks = vi.hoisted(() => ({ | ||
isAuthorized: false, | ||
region: 'US', | ||
agreements: [], | ||
})); | ||
|
||
const shellContext = { | ||
shell: { | ||
getPlugin: (plugin: string) => { | ||
if (plugin === 'navigation') { | ||
return { | ||
getURL: vi.fn( | ||
() => | ||
new Promise((resolve) => { | ||
setTimeout(() => resolve('http://fakelink.com'), 50); | ||
}), | ||
), | ||
}; | ||
} | ||
return { | ||
getEnvironment: () => ({ | ||
getRegion: vi.fn(() => mocks.region), | ||
}) | ||
}; | ||
}, | ||
} | ||
}; | ||
|
||
const queryClient = new QueryClient(); | ||
const renderComponent = () => { | ||
return render( | ||
<QueryClientProvider client={queryClient}> | ||
<ShellContext.Provider | ||
value={(shellContext as unknown) as ShellContextType} | ||
> | ||
<AgreementsUpdateModal /> | ||
</ShellContext.Provider> | ||
</QueryClientProvider>, | ||
); | ||
}; | ||
|
||
vi.mock('react', async (importOriginal) => { | ||
const module = await importOriginal<typeof import('react')>(); | ||
return { | ||
...module, | ||
useContext: () => shellContext | ||
} | ||
}); | ||
|
||
vi.mock('@/hooks/accountUrn/useAccountUrn', () => ({ | ||
default: () => () => 'urn' | ||
})); | ||
|
||
vi.mock('@ovh-ux/manager-react-components/src/hooks/iam', () => ({ | ||
useAuthorizationIam: () => () => ({ isAuthorized: mocks.isAuthorized }) | ||
})); | ||
|
||
vi.mock('@/hooks/agreements/useAgreementsUpdate', () => ({ | ||
default: () => ({ data: mocks.agreements }) | ||
})); | ||
|
||
describe('AgreementsUpdateModal', () => { | ||
it('should display nothing for US customers', () => { | ||
const { queryByTestId } = renderComponent(); | ||
expect(queryByTestId('agreements-update-modal')).not.toBeInTheDocument(); | ||
}); | ||
it('should display nothing for non US and non authorized customers', () => { | ||
mocks.region = 'EU'; | ||
const { queryByTestId } = renderComponent(); | ||
expect(queryByTestId('agreements-update-modal')).not.toBeInTheDocument(); | ||
}); | ||
it('should display a modal for non US and authorized customers without new contract', () => { | ||
mocks.isAuthorized = true; | ||
const { queryByTestId } = renderComponent(); | ||
expect(queryByTestId('agreements-update-modal')).not.toBeInTheDocument(); | ||
}); | ||
it('should display a modal for non US and authorized customers', () => { | ||
mocks.agreements.push({ agreed: false, id: 9999, contractId: 9999 }); | ||
const { getByTestId } = renderComponent(); | ||
expect(getByTestId('agreements-update-modal')).not.toBeNull(); | ||
}); | ||
}) |
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
38 changes: 38 additions & 0 deletions
38
packages/manager/apps/container/src/context/modals/ModalsProvider.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,38 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import ModalsContext, { ModalsContextType, ModalTypes } from './modals.context'; | ||
|
||
import { useShell } from '@/context'; | ||
|
||
type Props = { | ||
children: JSX.Element | JSX.Element[]; | ||
}; | ||
|
||
export const ModalsProvider = ({ children = null }: Props): JSX.Element => { | ||
const shell = useShell(); | ||
const uxPlugin = shell.getPlugin('ux'); | ||
const [current, setCurrent] = useState<ModalTypes>(ModalTypes.kyc); | ||
|
||
useEffect(() => { | ||
uxPlugin.registerModalActionDoneListener(() => { | ||
setCurrent((previous) => { | ||
if (previous === null) { | ||
return null; | ||
} | ||
return (previous < ModalTypes.agreements) ? (previous + 1 as ModalTypes) : null; | ||
}); | ||
}); | ||
}, []); | ||
|
||
const modalsContext: ModalsContextType = { | ||
current, | ||
}; | ||
|
||
return ( | ||
<ModalsContext.Provider value={modalsContext}> | ||
{children} | ||
</ModalsContext.Provider> | ||
); | ||
}; | ||
|
||
export default ModalsProvider; |
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 './ModalsProvider'; | ||
|
||
export { default as useModals } from './useModals'; |
15 changes: 15 additions & 0 deletions
15
packages/manager/apps/container/src/context/modals/modals.context.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 { createContext } from 'react'; | ||
|
||
export enum ModalTypes { | ||
kyc, | ||
payment, | ||
agreements, | ||
} | ||
|
||
export type ModalsContextType = { | ||
current: ModalTypes; | ||
}; | ||
|
||
const ModalsContext = createContext<ModalsContextType>({} as ModalsContextType); | ||
|
||
export default ModalsContext; |
6 changes: 6 additions & 0 deletions
6
packages/manager/apps/container/src/context/modals/useModals.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,6 @@ | ||
import { useContext } from 'react'; | ||
import ModalsContext from '@/context/modals/modals.context'; | ||
|
||
const useModals = () => useContext(ModalsContext); | ||
|
||
export default useModals; |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not do a separated PR for the common changes ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will disappear once their dedicated PR will be merged (#14025)