Skip to content

Commit

Permalink
Add enterprise upgrade modals when adding a network device (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-aleksander authored Jan 19, 2025
1 parent feef3f3 commit 49ffa0c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
} from '../../../../../../shared/defguard-ui/components/Layout/Button/types';
import { MessageBox } from '../../../../../../shared/defguard-ui/components/Layout/MessageBox/MessageBox';
import { MessageBoxType } from '../../../../../../shared/defguard-ui/components/Layout/MessageBox/types';
import { useAppStore } from '../../../../../../shared/hooks/store/useAppStore';
import { useAuthStore } from '../../../../../../shared/hooks/store/useAuthStore';
import { useEnterpriseUpgradeStore } from '../../../../../../shared/hooks/store/useEnterpriseUpgradeStore';
import useApi from '../../../../../../shared/hooks/useApi';
import { useToaster } from '../../../../../../shared/hooks/useToaster';
import { QueryKeys } from '../../../../../../shared/queries';
Expand Down Expand Up @@ -43,6 +45,10 @@ export const SetupCliStep = () => {
standaloneDevice: { createCliDevice },
} = useApi();

const showUpgradeToast = useEnterpriseUpgradeStore((s) => s.show);
const { getAppInfo } = useApi();
const setAppStore = useAppStore((s) => s.setState, shallow);

const { mutateAsync } = useMutation({
mutationFn: createCliDevice,
onSuccess: () => {
Expand All @@ -51,6 +57,14 @@ export const SetupCliStep = () => {
[QueryKeys.FETCH_USER_PROFILE, currentUserId],
[QueryKeys.FETCH_STANDALONE_DEVICE_LIST],
]);
void getAppInfo().then((response) => {
setAppStore({
appInfo: response,
});
if (response.license_info.any_limit_exceeded) {
showUpgradeToast();
}
});
},
onError: (e) => {
toast.error(LL.modals.addStandaloneDevice.toasts.creationFailed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
ButtonSize,
ButtonStyleVariant,
} from '../../../../../../shared/defguard-ui/components/Layout/Button/types';
import { useAppStore } from '../../../../../../shared/hooks/store/useAppStore';
import { useAuthStore } from '../../../../../../shared/hooks/store/useAuthStore';
import { useEnterpriseUpgradeStore } from '../../../../../../shared/hooks/store/useEnterpriseUpgradeStore';
import useApi from '../../../../../../shared/hooks/useApi';
import { QueryKeys } from '../../../../../../shared/queries';
import { generateWGKeys } from '../../../../../../shared/utils/generateWGKeys';
Expand Down Expand Up @@ -47,13 +49,25 @@ export const SetupManualStep = () => {
standaloneDevice: { createManualDevice: createDevice },
} = useApi();

const showUpgradeToast = useEnterpriseUpgradeStore((s) => s.show);
const { getAppInfo } = useApi();
const setAppStore = useAppStore((s) => s.setState, shallow);

const { mutateAsync } = useMutation({
mutationFn: createDevice,
onSuccess: () => {
invalidateMultipleQueries(queryClient, [
[QueryKeys.FETCH_USER_PROFILE, currentUserId],
[QueryKeys.FETCH_STANDALONE_DEVICE_LIST],
]);
void getAppInfo().then((response) => {
setAppStore({
appInfo: response,
});
if (response.license_info.any_limit_exceeded) {
showUpgradeToast();
}
});
},
});

Expand Down

0 comments on commit 49ffa0c

Please sign in to comment.