-
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
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4795865
feat(container): added an invitation modal to accept contract
4b43203
feat(container): add agreements update modal tests
b5b2333
feat(container): added aggreements modal and reviewed modals display
697fbb2
feat(container): added aggreements modal and reviewed modals display
87404d3
feat(container): added aggreements modal and reviewed modals display
5d980d4
feat(container): remove unnecessary comment
4f5fe6d
feat(container): fixed typo in agreements update modal redirection url
a002e34
feat(container): fixed agreements update modal display management
4a216a2
feat(container): fixed agreements update modal tests
236c855
feat(container): fixed kyc modal management
62a2c44
feat(container): fixed agreements and kyc india modals workflows
ad73f5c
fix(i18n): add missing translations [CDS 3592]
ee682fc
feat(billing): backport the new code to billing app
6d0f61c
fix(container): update variable names and dependencies
1da363a
feat(container): enhanced readability by splitting code and comments
4deee7f
feat(container): adjusted condition to handle agreement modal lifecycle
8f12791
feat(container): handle redirection for dedicated and new-billing
49000d3
feat(container): adjusted agreements modal lifecycle management
b2d6293
feat(container): adjusted mocks for agreements modal tests
4a3efbf
feat(account): backport account code from dedicated
1e082ad
feat(container): fixed agreements page links
d6acbae
feat(container): fixed agreement redirection url
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { fetchIcebergV6, FilterComparator } from "@ovh-ux/manager-core-api"; | ||
|
||
const fetchPendingAgreements = async () => { | ||
const { data } = await fetchIcebergV6({ | ||
route: '/me/agreements', | ||
filters: [{ key: 'agreed', comparator: FilterComparator.IsIn, value: ['todo', 'ko'] }], | ||
}); | ||
return data; | ||
}; | ||
|
||
export default fetchPendingAgreements; |
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,18 @@ | ||
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', | ||
}); | ||
|
||
return data[0]?.urn; | ||
}; |
File renamed without changes
151 changes: 151 additions & 0 deletions
151
...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,151 @@ | ||
import React, { useContext, useEffect, useMemo, useState } from 'react'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
import { | ||
ODS_THEME_COLOR_HUE, | ||
ODS_THEME_COLOR_INTENT, | ||
ODS_THEME_TYPOGRAPHY_SIZE, | ||
} from '@ovhcloud/ods-common-theming'; | ||
import { | ||
OsdsButton, | ||
OsdsLink, | ||
OsdsModal, | ||
OsdsText, | ||
} from '@ovhcloud/ods-components/react'; | ||
import { OdsHTMLAnchorElementTarget } from '@ovhcloud/ods-common-core'; | ||
import { | ||
ODS_BUTTON_SIZE, | ||
ODS_BUTTON_VARIANT, | ||
ODS_TEXT_LEVEL, | ||
} from '@ovhcloud/ods-components'; | ||
import { useAuthorizationIam } from '@ovh-ux/manager-react-components'; | ||
import usePendingAgreements from '@/hooks/agreements/usePendingAgreements'; | ||
import ApplicationContext from '@/context'; | ||
import ovhCloudLogo from '@/assets/images/logo-ovhcloud.png'; | ||
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 environment = shell | ||
.getPlugin('environment') | ||
.getEnvironment(); | ||
const region: string = environment.getRegion(); | ||
const navigation = shell.getPlugin('navigation'); | ||
const { current } = useModals(); | ||
// TODO: simplify this once new-billing is fully open to the public | ||
const isNewBillingAvailable = Boolean(environment.getApplicationURL('new-billing')); | ||
const billingAppName = isNewBillingAvailable ? 'new-billing' : 'dedicated'; | ||
const billingAppPath = `#${isNewBillingAvailable ? '' : 'billing/'}/autorenew/agreements`; | ||
const myContractsLink = navigation.getURL(billingAppName, billingAppPath); | ||
const [ showModal, setShowModal ] = useState(false); | ||
const isCurrentModalActive = useMemo(() => current === ModalTypes.agreements, [current]); | ||
const isOnAgreementsPage = useMemo(() => window.location.href === myContractsLink, [window.location.href]); | ||
const isFeatureAvailable = useMemo(() => region !== 'US', [region]); | ||
const { t } = useTranslation('agreements-update-modal'); | ||
const { data: urn } = useAccountUrn({ enabled: isCurrentModalActive && !isOnAgreementsPage && isFeatureAvailable }); | ||
const { isAuthorized: canUserAcceptAgreements, isLoading: isAuthorizationLoading } = useAuthorizationIam(['account:apiovh:me/agreements/accept'], urn); | ||
const { data: agreements, isLoading: areAgreementsLoading } = usePendingAgreements({ enabled: canUserAcceptAgreements }); | ||
const goToContractPage = () => { | ||
setShowModal(false); | ||
navigation.navigateTo(billingAppName, billingAppPath); | ||
}; | ||
|
||
/* | ||
Since we don't want to display multiple modals at the same time we "watch" the `current` modal, and once it is | ||
the agreements modal turn, we will try to display it (if conditions are met) or switch to the next one otherwise. | ||
As a result, only once the agreements modal is the current one will we manage the modal lifecycle. | ||
Lifecycle management: | ||
- If user is on the agreements page, we will not display the modal and let the page notify for modal change | ||
once the user accept non-validated agreements or leave the page | ||
- Wait until all necessary data (IAM authorization, non-validated agreements list) are loaded | ||
- Once we have the data, check if they allow the display of the modal (IAM authorized + at least one non-validated | ||
agreement), if the conditions are met, we show the modal, otherwise we switch to the next one | ||
*/ | ||
useEffect(() => { | ||
if (!isCurrentModalActive) return; | ||
|
||
if (isFeatureAvailable) { | ||
const hasFullyLoaded = | ||
urn && | ||
!isAuthorizationLoading && | ||
(!canUserAcceptAgreements || !areAgreementsLoading); | ||
if (isOnAgreementsPage || !hasFullyLoaded) return; | ||
|
||
if (!agreements?.length) { | ||
shell.getPlugin('ux').notifyModalActionDone(); | ||
} else { | ||
setShowModal(true); | ||
} | ||
} else { | ||
shell.getPlugin('ux').notifyModalActionDone(); | ||
} | ||
return; | ||
}, [ | ||
isCurrentModalActive, | ||
isFeatureAvailable, | ||
isOnAgreementsPage, | ||
isAuthorizationLoading, | ||
canUserAcceptAgreements, | ||
areAgreementsLoading, | ||
agreements, | ||
]); | ||
|
||
return showModal ? ( | ||
<> | ||
<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"> | ||
<Trans | ||
i18nKey="agreements_update_modal_description" | ||
t={t} | ||
components={{ | ||
anchor: ( | ||
<OsdsLink | ||
href={myContractsLink} | ||
target={OdsHTMLAnchorElementTarget._top} | ||
onClick={() => setShowModal(false)} | ||
></OsdsLink> | ||
), | ||
}} | ||
/> | ||
</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; | ||
} |
100 changes: 100 additions & 0 deletions
100
...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,100 @@ | ||
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'; | ||
import { ModalTypes } from '@/context/modals/modals.context'; | ||
|
||
const mocks = vi.hoisted(() => ({ | ||
isAuthorized: false, | ||
region: 'US', | ||
agreements: [], | ||
})); | ||
|
||
const shellContext = { | ||
shell: { | ||
getPlugin: (plugin: string) => { | ||
switch (plugin) { | ||
case 'navigation': return { | ||
getURL: vi.fn( | ||
() => | ||
new Promise((resolve) => { | ||
setTimeout(() => resolve('http://fakelink.com'), 50); | ||
}), | ||
), | ||
}; | ||
case 'ux': return { | ||
notifyModalActionDone: vi.fn(), | ||
}; | ||
case 'environment': return { | ||
getEnvironment: () => ({ | ||
getRegion: vi.fn(() => mocks.region), | ||
getApplicationURL: vi.fn((app) => `https://ovh.com/manager/${app}`) | ||
}) | ||
}; | ||
} | ||
}, | ||
} | ||
}; | ||
|
||
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: () => ({ data: 'urn' }), | ||
})); | ||
|
||
vi.mock('@ovh-ux/manager-react-components', () => ({ | ||
useAuthorizationIam: () => ({ isAuthorized: mocks.isAuthorized }) | ||
})); | ||
|
||
vi.mock('@/context/modals', () => ({ | ||
useModals: () => ({ current: ModalTypes.agreements }) | ||
})); | ||
|
||
vi.mock('@/hooks/agreements/usePendingAgreements', () => ({ | ||
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 nothing 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; |
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.
A custom hook should imho check if the hook is used inside the provider and otherwise throw an error. Sth like: