@antscorp/antsomi-ui 1.3.5-beta.585 → 1.3.5-beta.586
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/molecules/AccountSelection/AccountListing.js +11 -2
- package/es/components/molecules/AccountSelection/hooks/useAccountSelection.d.ts +1 -0
- package/es/components/molecules/AccountSelection/hooks/useAccountSelection.js +5 -2
- package/es/queries/Account/useGetAccountList.d.ts +11 -2
- package/es/queries/Account/useGetAccountList.js +11 -2
- package/es/services/Account/index.d.ts +7 -0
- package/es/services/Account/index.js +28 -0
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ export const AccountListing = React.forwardRef((props, ref) => {
|
|
|
12
12
|
const { className, apiConfig, showAllAccount = true, currentAccount = '', onChange } = props;
|
|
13
13
|
// States
|
|
14
14
|
const [searchValue, setSearchValue] = useState('');
|
|
15
|
-
const { accountData, recentData } = useAccountSelection(apiConfig);
|
|
15
|
+
const { accountData, recentData, updateRecentAccount } = useAccountSelection(apiConfig);
|
|
16
16
|
const isAllAccount = currentAccount === 'all';
|
|
17
17
|
useImperativeHandle(ref, () => ({
|
|
18
18
|
getUsers() {
|
|
@@ -21,8 +21,17 @@ export const AccountListing = React.forwardRef((props, ref) => {
|
|
|
21
21
|
}), [recentData, accountData]);
|
|
22
22
|
// Handlers
|
|
23
23
|
const handleSelectAccount = useCallback((userId) => {
|
|
24
|
+
const currentRecent = (recentData === null || recentData === void 0 ? void 0 : recentData.value) || [];
|
|
25
|
+
const body = userId !== currentRecent[0]
|
|
26
|
+
? [userId, currentRecent[0]]
|
|
27
|
+
: currentRecent[1]
|
|
28
|
+
? [userId, currentRecent[1]]
|
|
29
|
+
: [userId, currentRecent[0]];
|
|
30
|
+
updateRecentAccount(body.map(id => Number(id)));
|
|
24
31
|
onChange === null || onChange === void 0 ? void 0 : onChange(userId);
|
|
25
|
-
},
|
|
32
|
+
},
|
|
33
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
+
[onChange, recentData]);
|
|
26
35
|
return (React.createElement(AccountSelectionStyled, { className: className },
|
|
27
36
|
React.createElement(Input, { placeholder: "Search", suffix: React.createElement(Icon, { type: "icon-ants-search-2", style: { fontSize: '24px', color: (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.bw8 } }), value: searchValue, onChange: event => setSearchValue(event.target.value) }),
|
|
28
37
|
React.createElement("div", { className: "account-list" },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
// Queries
|
|
4
|
-
import { useGetAccountList, useGetPermissionAccountList, useGetRecentAccount, } from '@antscorp/antsomi-ui/es/queries';
|
|
4
|
+
import { useGetAccountList, useGetPermissionAccountList, useGetRecentAccount, useUpdateRecentAccount, } from '@antscorp/antsomi-ui/es/queries';
|
|
5
5
|
// Constant
|
|
6
6
|
import { APP_CODES } from '@antscorp/antsomi-ui/es/constants';
|
|
7
7
|
const { APP_ANTALYSER, DATAFLOWS } = APP_CODES;
|
|
@@ -41,6 +41,9 @@ export const useAccountSelection = (apiConfig) => {
|
|
|
41
41
|
enabled: !isUsePermissionAccount(appCode || ''),
|
|
42
42
|
},
|
|
43
43
|
});
|
|
44
|
+
const { mutateAsync: updateRecentAccount } = useUpdateRecentAccount({
|
|
45
|
+
apiConfig,
|
|
46
|
+
});
|
|
44
47
|
// Memos
|
|
45
48
|
const accountData = useMemo(() => {
|
|
46
49
|
if (isUsePermissionAccount(appCode || '')) {
|
|
@@ -53,5 +56,5 @@ export const useAccountSelection = (apiConfig) => {
|
|
|
53
56
|
}
|
|
54
57
|
return (data === null || data === void 0 ? void 0 : data.entries) || [];
|
|
55
58
|
}, [appCode, data === null || data === void 0 ? void 0 : data.entries, permissionAccountList]);
|
|
56
|
-
return { recentData, accountData };
|
|
59
|
+
return { recentData, accountData, updateRecentAccount };
|
|
57
60
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
-
import { TAccountParams } from '../../services/Account';
|
|
1
|
+
import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
2
|
+
import { TAccountParams, TUpdateRecentAccount } from '../../services/Account';
|
|
3
3
|
import { AccountListing, AccountRecent, TAccountPermission } from '../../models/AccountListing';
|
|
4
4
|
type OptionHasDefault = 'queryKey' | 'queryFn';
|
|
5
5
|
type GetAccountListProps = {
|
|
@@ -10,11 +10,20 @@ type GetRecentAccountProps = {
|
|
|
10
10
|
apiConfig: TAccountParams;
|
|
11
11
|
options?: Omit<UseQueryOptions<any, any, AccountRecent, any[]>, OptionHasDefault>;
|
|
12
12
|
};
|
|
13
|
+
type UpdateRecentAccountProps = {
|
|
14
|
+
apiConfig: TAccountParams;
|
|
15
|
+
options?: UseMutationOptions<{
|
|
16
|
+
status: number;
|
|
17
|
+
}, any, TUpdateRecentAccount['data'], unknown>;
|
|
18
|
+
};
|
|
13
19
|
type TCheckUserPermissionProps = {
|
|
14
20
|
apiConfig: TAccountParams;
|
|
15
21
|
options?: Omit<UseQueryOptions<any, any, TAccountPermission | undefined, any[]>, OptionHasDefault>;
|
|
16
22
|
};
|
|
17
23
|
export declare const useGetAccountList: (props: GetAccountListProps) => import("@tanstack/react-query").UseQueryResult<AccountListing, any>;
|
|
18
24
|
export declare const useGetRecentAccount: (props: GetRecentAccountProps) => import("@tanstack/react-query").UseQueryResult<AccountRecent, any>;
|
|
25
|
+
export declare const useUpdateRecentAccount: (props: UpdateRecentAccountProps) => import("@tanstack/react-query").UseMutationResult<{
|
|
26
|
+
status: number;
|
|
27
|
+
}, any, [number, number], unknown>;
|
|
19
28
|
export declare const useCheckUserPermission: (props: TCheckUserPermissionProps) => import("@tanstack/react-query").UseQueryResult<TAccountPermission | undefined, any>;
|
|
20
29
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Libraries
|
|
2
|
-
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { useQuery, useMutation, useQueryClient, } from '@tanstack/react-query';
|
|
3
3
|
// Services
|
|
4
4
|
import { accountService } from '../../services/Account';
|
|
5
5
|
// Constants
|
|
6
6
|
import { QUERY_KEYS } from '../../constants/queries';
|
|
7
|
-
const { getList, getRecentAccount, checkPermission } = accountService;
|
|
7
|
+
const { getList, getRecentAccount, updateRecentAccount, checkPermission } = accountService;
|
|
8
8
|
export const useGetAccountList = (props) => {
|
|
9
9
|
const { apiConfig, options } = props;
|
|
10
10
|
return useQuery(Object.assign({ queryKey: [QUERY_KEYS.GET_ACCOUNT_LISTING, apiConfig], queryFn: () => getList(apiConfig) }, options));
|
|
@@ -13,6 +13,15 @@ export const useGetRecentAccount = (props) => {
|
|
|
13
13
|
const { apiConfig, options } = props;
|
|
14
14
|
return useQuery(Object.assign({ queryKey: [QUERY_KEYS.GET_RECENT_ACCOUNT], queryFn: () => getRecentAccount(apiConfig) }, options));
|
|
15
15
|
};
|
|
16
|
+
export const useUpdateRecentAccount = (props) => {
|
|
17
|
+
const { apiConfig, options } = props;
|
|
18
|
+
const queryClient = useQueryClient();
|
|
19
|
+
return useMutation(Object.assign({ mutationFn: variables => updateRecentAccount({ params: apiConfig, data: variables }), onSettled: () => {
|
|
20
|
+
queryClient.invalidateQueries([QUERY_KEYS.GET_RECENT_ACCOUNT], {
|
|
21
|
+
exact: false,
|
|
22
|
+
});
|
|
23
|
+
} }, options));
|
|
24
|
+
};
|
|
16
25
|
export const useCheckUserPermission = (props) => {
|
|
17
26
|
const { apiConfig, options } = props;
|
|
18
27
|
const { languageCode, userId, portalId } = apiConfig;
|
|
@@ -7,8 +7,15 @@ export type TAccountParams = {
|
|
|
7
7
|
accountId?: number;
|
|
8
8
|
token?: string;
|
|
9
9
|
};
|
|
10
|
+
export type TUpdateRecentAccount = {
|
|
11
|
+
params: TAccountParams;
|
|
12
|
+
data: [number, number];
|
|
13
|
+
};
|
|
10
14
|
export declare const accountService: {
|
|
11
15
|
getList: (config: TAccountParams) => Promise<AccountListing>;
|
|
12
16
|
getRecentAccount: (config: TAccountParams) => Promise<AccountRecent | undefined>;
|
|
13
17
|
checkPermission: (config: TAccountParams) => Promise<TAccountPermission>;
|
|
18
|
+
updateRecentAccount: (args: TUpdateRecentAccount) => Promise<{
|
|
19
|
+
status: number;
|
|
20
|
+
}>;
|
|
14
21
|
};
|
|
@@ -86,4 +86,32 @@ export const accountService = {
|
|
|
86
86
|
return Promise.reject(error);
|
|
87
87
|
}
|
|
88
88
|
}),
|
|
89
|
+
updateRecentAccount: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const { params, data } = args;
|
|
91
|
+
const { domain, languageCode = 'en', portalId = 33167, userId, token } = params;
|
|
92
|
+
try {
|
|
93
|
+
const response = yield axios({
|
|
94
|
+
method: 'PUT',
|
|
95
|
+
url: `${domain}${API_RECENT}`,
|
|
96
|
+
params: {
|
|
97
|
+
portalId,
|
|
98
|
+
languageCode,
|
|
99
|
+
_user_id: userId,
|
|
100
|
+
},
|
|
101
|
+
headers: {
|
|
102
|
+
Token: token,
|
|
103
|
+
},
|
|
104
|
+
data: {
|
|
105
|
+
value: JSON.stringify(data),
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
status: +get(response, 'data.data.status', ''),
|
|
110
|
+
};
|
|
111
|
+
// return undefined;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return Promise.reject(error);
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
89
117
|
};
|