Skip to content

Commit 0890a6e

Browse files
Axel-IoBuildersAlbertoMolinaIoBuildersluigi-ioManuIOBjaime-iobermudez
authored andcommitted
feat: add bond beneficiaries (#660)
Signed-off-by: Alberto Molina <[email protected]> Signed-off-by: Axel Loupias <[email protected]> Signed-off-by: Luigi Navarro <[email protected]> Signed-off-by: Manu Fernández <[email protected]> Signed-off-by: jaime-iobermudez <[email protected]> Co-authored-by: Alberto Molina <[email protected]> Co-authored-by: Luigi Navarro <[email protected]> Co-authored-by: Manu Fernández <[email protected]> Co-authored-by: jaime-iobermudez <[email protected]> Signed-off-by: Axel-IoBuilders <[email protected]> Signed-off-by: Mario Francia <[email protected]>
1 parent db72d96 commit 0890a6e

File tree

115 files changed

+14042
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+14042
-51
lines changed

apps/ats/web/eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ const webConfig = baseConfig
5252
},
5353
]);
5454

55-
export default webConfig;
55+
export default webConfig;

apps/ats/web/prettier.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
*/
55
import baseConfig from '../../../prettier.config.mjs';
66

7-
export default baseConfig;
7+
export default baseConfig;
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import { useMutation, useQueryClient } from '@tanstack/react-query';
2+
import SDKService from '../../services/SDKService';
3+
import {
4+
AddBeneficiaryRequest,
5+
RemoveBeneficiaryRequest,
6+
UpdateBeneficiaryDataRequest,
7+
} from '@hashgraph/asset-tokenization-sdk';
8+
import { useToast } from 'io-bricks-ui';
9+
import { useTranslation } from 'react-i18next';
10+
import { GET_BENEFICIARY_LIST } from '../queries/useBeneficiaries';
11+
12+
export const useAddBeneficiary = () => {
13+
const queryClient = useQueryClient();
14+
const toast = useToast();
15+
const { t } = useTranslation('security', {
16+
keyPrefix: 'details.beneficiaries.create.messages',
17+
});
18+
19+
return useMutation(
20+
(req: AddBeneficiaryRequest) => SDKService.addBeneficiary(req),
21+
{
22+
onSuccess(data, variables) {
23+
queryClient.invalidateQueries({
24+
queryKey: [GET_BENEFICIARY_LIST(variables.securityId)],
25+
});
26+
27+
console.log(
28+
'SDK message --> Add beneficiary operation success: ',
29+
data,
30+
);
31+
32+
if (!data) {
33+
return;
34+
}
35+
36+
toast.show({
37+
duration: 3000,
38+
title: t('success'),
39+
description: t('descriptionSuccess'),
40+
variant: 'subtle',
41+
status: 'success',
42+
});
43+
},
44+
onError: (error) => {
45+
console.log('SDK message --> Add beneficiary operation error: ', error);
46+
47+
toast.show({
48+
duration: 3000,
49+
title: t('error'),
50+
description: t('descriptionFailed'),
51+
variant: 'subtle',
52+
status: 'error',
53+
});
54+
},
55+
},
56+
);
57+
};
58+
59+
export const useUpdateBeneficiary = () => {
60+
const queryClient = useQueryClient();
61+
const toast = useToast();
62+
const { t } = useTranslation('security', {
63+
keyPrefix: 'details.beneficiaries.update.messages',
64+
});
65+
66+
return useMutation(
67+
(req: UpdateBeneficiaryDataRequest) =>
68+
SDKService.updateBeneficiaryData(req),
69+
{
70+
onSuccess(data, variables) {
71+
queryClient.invalidateQueries({
72+
queryKey: [GET_BENEFICIARY_LIST(variables.securityId)],
73+
});
74+
75+
console.log(
76+
'SDK message --> Update beneficiary operation success: ',
77+
data,
78+
);
79+
80+
if (!data) {
81+
return;
82+
}
83+
84+
toast.show({
85+
duration: 3000,
86+
title: t('success'),
87+
description: t('descriptionSuccess'),
88+
variant: 'subtle',
89+
status: 'success',
90+
});
91+
},
92+
onError: (error) => {
93+
console.log(
94+
'SDK message --> Update beneficiary operation error: ',
95+
error,
96+
);
97+
98+
toast.show({
99+
duration: 3000,
100+
title: t('error'),
101+
description: t('descriptionFailed'),
102+
variant: 'subtle',
103+
status: 'error',
104+
});
105+
},
106+
},
107+
);
108+
};
109+
110+
export const useRemoveBeneficiary = () => {
111+
const queryClient = useQueryClient();
112+
const toast = useToast();
113+
const { t } = useTranslation('security', {
114+
keyPrefix: 'details.beneficiaries.remove.messages',
115+
});
116+
117+
return useMutation(
118+
(req: RemoveBeneficiaryRequest) => SDKService.removeBeneficiary(req),
119+
{
120+
onSuccess(data, variables) {
121+
queryClient.invalidateQueries({
122+
queryKey: [GET_BENEFICIARY_LIST(variables.securityId)],
123+
});
124+
125+
console.log(
126+
'SDK message --> Remove beneficiary operation success: ',
127+
data,
128+
);
129+
130+
if (!data) {
131+
return;
132+
}
133+
134+
toast.show({
135+
duration: 3000,
136+
title: t('success'),
137+
description: t('descriptionSuccess'),
138+
variant: 'subtle',
139+
status: 'success',
140+
});
141+
},
142+
onError: (error) => {
143+
console.log(
144+
'SDK message --> Remove beneficiary operation error: ',
145+
error,
146+
);
147+
148+
toast.show({
149+
duration: 3000,
150+
title: t('error'),
151+
description: t('descriptionFailed'),
152+
variant: 'subtle',
153+
status: 'error',
154+
});
155+
},
156+
},
157+
);
158+
};

0 commit comments

Comments
 (0)