Skip to content
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
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

JacquesLarique
Copy link
Contributor

Question Answer
Branch? master
Bug fix? no
New feature? yes
Breaking change? no
Tickets MANAGER-14722
License BSD 3-Clause
  • Try to keep pull requests small so they can be easily reviewed.
  • Commits are signed-off
  • Only FR translations have been updated
  • Branch is up-to-date with target branch
  • Lint has passed locally
  • Standalone app was ran and tested locally
  • Ticket reference is mentioned in linked commits (internal only)
  • Breaking change is mentioned in relevant commits (n/a)

Description

Reworked modal display in order to avoid the possibility of having multiple modals displayed at the same time
Set up a new modal to invite customer to accept new / updated contracts
Fix a small tracking issue on KYC India modal

Related

Copy link
Contributor

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 ?

Copy link
Contributor Author

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)

MaximeBajeux
MaximeBajeux previously approved these changes Nov 13, 2024
const { data } = await fetchIcebergV2<IamResource>({
route: '/iam/resource?resourceType=account',
});
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note to say why it s commented

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, isLoading } = useAgreementsUpdate({ enabled: canUserAcceptAgreements });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isloading is not used

@@ -22,6 +25,7 @@ export default function Container(): JSX.Element {
chatbotReduced,
setChatbotReduced,
} = useContainer();
useModals();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it is on oversight ?

oalkabouss
oalkabouss previously approved these changes Nov 13, 2024
MaximeBajeux
MaximeBajeux previously approved these changes Nov 13, 2024
MaximeBajeux
MaximeBajeux previously approved these changes Nov 20, 2024
oalkabouss
oalkabouss previously approved these changes Nov 20, 2024
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

oalkabouss
oalkabouss previously approved these changes Dec 5, 2024
MaximeBajeux
MaximeBajeux previously approved these changes Dec 5, 2024
@github-actions github-actions bot added the has conflicts Has conflicts to resolve before merging label Dec 12, 2024
MaximeBajeux
MaximeBajeux previously approved these changes Jan 2, 2025
@MaximeBajeux MaximeBajeux changed the base branch from master to release/gcj-w1 January 3, 2025 08:02
sachinrameshn
sachinrameshn previously approved these changes Jan 3, 2025
@sachinrameshn sachinrameshn self-requested a review January 3, 2025 08:08
@@ -0,0 +1,11 @@
import { fetchIcebergV6, FilterComparator } from "@ovh-ux/manager-core-api";

const fetchAgreementsUpdates = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Considering the filters applied, it would make more sense to use more precise function name.

Suggested change
const fetchAgreementsUpdates = async () => {
const fetchPendingAgreements = async () => {

Comment on lines 5 to 10
const useAgreementsUpdate = (options?: Partial<DefinedInitialDataOptions<Agreements[]>>) =>
useQuery({
...options,
queryKey: ['agreements'],
queryFn: fetchAgreementsUpdates,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as https://github.com/ovh/manager/pull/14041/files#r1901556827 + Query key is too subtle with no info regarding the applied filters. It can easily induce errors if same key is used with different filters.

Suggested change
const useAgreementsUpdate = (options?: Partial<DefinedInitialDataOptions<Agreements[]>>) =>
useQuery({
...options,
queryKey: ['agreements'],
queryFn: fetchAgreementsUpdates,
});
const usePendingAgreements = (options?: Partial<DefinedInitialDataOptions<Agreements[]>>) =>
useQuery({
...options,
queryKey: ['agreements'],
queryFn: fetchAgreementsUpdates,
});

ref: MANAGER-14722

Signed-off-by: Maxime Bajeux <[email protected]>
};

useEffect(() => {
const shouldManageModal = region !== 'US' && current === ModalTypes.agreements && window.location.href !== myContractsLink;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: This logic is repeated in L29. I think we should extract it to function.

Comment on lines 41 to 58
// We consider we have loaded all information if conditions are not respected to try to display the modal
const hasFullyLoaded = !shouldManageModal
// Or authorization are loaded but user does have right to accept contract or has no contract to accept
|| !isAuthorizationLoading && (!canUserAcceptAgreements || !areAgreementsLoading);
// We handle the modal display only when the Agreements modal is the current one, contract management is available
// (region is not US) and we are not on the page where the user can do the related action (accepts his contract)
if (shouldManageModal) {
// We will wait for all data to be retrieved before handling the modal lifecycle
if (hasFullyLoaded) {
// If no contract are to be accepted we go to the next modal (if it exists)
if (!agreements?.length) {
shell.getPlugin('ux').notifyModalActionDone();
}
// Otherwise we display the modal
else {
setShowModal(true);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Instead of spreading the comments per line, it's better to comment the business requirements at the top of useEffect. This way we create distinction between code and comment and does not break the continuity if one wants to read only the code/comment.

Comment on lines 71 to 95
const shouldManageModal = current === ModalTypes.kyc && window.location.href !== kycURL;
// We handle the modal display only when the KYC modal is the current one, and we are not on the page
// where the user can do the related action (upload his documents)
if (shouldManageModal) {
// We will wait for feature availability response before handling the modal lifecycle
if (!isFeatureAvailabilityLoading && availability) {
// If the KYC feature is not available we can safely switch to the next modal
if (!isKycAvailable) {
shell.getPlugin('ux').notifyModalActionDone();
}
// Otherwise we will wait for the KYC procedure status to decide either we display th modal or switch to the
// next one
else if (!isProcedureStatusLoading && statusDataResponse) {
// If the procedure's status is 'required' we display the modal
if (statusDataResponse?.data?.status === requiredStatusKey) {
setShowModal(true);
}
// Otherwise we go to the next modal (if it exists)
else if (shouldManageModal) {
shell.getPlugin('ux').notifyModalActionDone();
}
}
}
}
}, [statusDataResponse?.data?.status]);
}, [current, isFeatureAvailabilityLoading, availability, isKycAvailable, isProcedureStatusLoading, statusDataResponse]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaximeBajeux MaximeBajeux changed the base branch from release/gcj-w1 to master January 3, 2025 15:19
@MaximeBajeux MaximeBajeux dismissed stale reviews from sachinrameshn and themself January 3, 2025 15:19

The base branch was changed.

anooparveti
anooparveti previously approved these changes Jan 7, 2025
Jacques Larique added 5 commits January 9, 2025 09:26
ref: MANAGER-14722

Signed-off-by: Jacques Larique <[email protected]>
ref: MANAGER-14722

Signed-off-by: Jacques Larique <[email protected]>
ref: MANAGER-14722

Signed-off-by: Jacques Larique <[email protected]>
ref: MANAGER-14722

Signed-off-by: Jacques Larique <[email protected]>
ref: MANAGER-14722

Signed-off-by: Jacques Larique <[email protected]>
MaximeBajeux
MaximeBajeux previously approved these changes Jan 10, 2025
ref: MANAGER-14722

Signed-off-by: Jacques Larique <[email protected]>
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
7.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants