Skip to content

Commit

Permalink
fix(desktop):fix merge user (#5101)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudaotutou authored Oct 8, 2024
1 parent a9154f8 commit 6489ce6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { mergeUserRequest } from '@/api/auth';
import { useCustomToast } from '@/hooks/useCustomToast';
import useCallbackStore, { MergeUserStatus } from '@/stores/callback';
import { ValueOf } from '@/types';
import { I18nErrorKey } from '@/types/i18next';
import { USER_MERGE_STATUS } from '@/types/response/merge';
import {
Text,
BoxProps,
Button,
HStack,
Modal,
ModalOverlay,
ModalContent,
ModalBody,
ModalCloseButton,
ModalContent,
ModalHeader,
ModalOverlay,
Spinner,
ModalBody,
BoxProps,
VStack,
HStack
Text,
VStack
} from '@chakra-ui/react';
import { WarnTriangeIcon } from '@sealos/ui';
import { useQueryClient, useMutation } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useTranslation } from 'next-i18next';
import { mergeUserRequest } from '@/api/auth';
import useCallbackStore, { MergeUserStatus } from '@/stores/callback';
import { useEffect, useState } from 'react';
import { USER_MERGE_STATUS } from '@/types/response/merge';
import { ValueOf } from '@/types';
import { I18nErrorKey } from '@/types/i18next';

function NeedToMerge({ ...props }: BoxProps & {}) {
const { mergeUserStatus, mergeUserData, setMergeUserStatus, setMergeUserData } =
Expand Down Expand Up @@ -63,28 +63,30 @@ function NeedToMerge({ ...props }: BoxProps & {}) {
<Modal isOpen={isOpen} onClose={onClose} isCentered>
<ModalOverlay />
<ModalContent
borderRadius={'12px'}
borderRadius={'10px'}
maxW={'400px'}
bgColor={'#FFF'}
backdropFilter="blur(150px)"
p="24px"
>
<ModalCloseButton right={'24px'} top="24px" p="0" />
<ModalCloseButton top={'8px'} right={'20px'} />
<ModalHeader
px={'20px'}
py={'12px'}
bg={'grayModern.25'}
borderBottomWidth={'1px'}
borderBottomColor={'grayModern.100'}
p="0"
borderBottom={'1px solid'}
fontWeight={500}
fontSize={'16px'}
display={'flex'}
gap={'10px'}
borderColor={'grayModern.100'}
>
<WarnTriangeIcon boxSize={'24px'} fill={'yellow.500'} />
<Text>{t('common:merge_account_title')}</Text>
</ModalHeader>
{mutation.isLoading ? (
<Spinner mx="auto" />
) : (
<ModalBody h="100%" w="100%" p="0" mt="22px" fontSize={'14px'}>
<ModalBody h="100%" w="100%" px="36px" pt="24px" pb="32px" fontSize={'14px'}>
<VStack alignItems={'stretch'} gap={'0'}>
<Text mb={'12px'}>
{mergeUserStatus === MergeUserStatus.CONFLICT
Expand Down
37 changes: 24 additions & 13 deletions frontend/desktop/src/services/backend/cronjob/mergeUserCr.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { globalPrisma, prisma } from '../db/init';
import { TransactionStatus, TransactionType } from 'prisma/global/generated/client';
import { JoinStatus } from 'prisma/region/generated/client';
import { getBillingUrl, getCvmUrl, getRegionUid, getWorkorderUrl } from '@/services/enable';
import { CronJobStatus } from '@/services/backend/cronjob/index';
import { getUserKubeconfigNotPatch } from '@/services/backend/kubernetes/admin';
import { mergeUserModifyBinding, mergeUserWorkspaceRole } from '@/services/backend/team';
import axios from 'axios';
import { generateCronJobToken } from '../auth';
import { getBillingUrl, getCvmUrl, getRegionUid, getWorkorderUrl } from '@/services/enable';
import { MergeUserEvent } from '@/types/db/event';
import axios from 'axios';
import { TransactionStatus, TransactionType } from 'prisma/global/generated/client';
import { JoinStatus } from 'prisma/region/generated/client';
import { generateBillingToken, generateCronJobToken } from '../auth';
import { globalPrisma, prisma } from '../db/init';

/**
* | | user is exist | user is not exist |
Expand Down Expand Up @@ -190,13 +190,24 @@ export class MergeUserCrJob implements CronJobStatus {
const kubeConfig = await getUserKubeconfigNotPatch(finalUserCr.crName);
if (!kubeConfig) throw Error('the kubeconfig for ' + finalUserCr.crName + ' is not found');
const [transferResult, workorderResult, cvmResult] = await Promise.all([
axios.post(billingUrl, {
kubeConfig,
owner: finalUserCr.crName,
userid: mergeUser.id,
toUser: user.id,
transferAll: true
}),
axios.post(
billingUrl,
{
userid: mergeUser.id,
toUser: user.id,
transferAll: true
},
{
headers: {
Authorization:
'Bearer ' +
generateBillingToken({
userUid: mergeUser.uid,
userId: mergeUser.id
})
}
}
),
axios.post(workorderUrl, {
token: generateCronJobToken({
userUid: user.id,
Expand Down

0 comments on commit 6489ce6

Please sign in to comment.