@autobusal/admin-api-consumers 1.2.0 → 1.2.1
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/CHANGELOG.md +6 -0
- package/TokenManager.tsx +1 -1
- package/package.json +1 -1
- package/services.ts +38 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.1
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **The token panel updates without a reload** - toggle/revoke/regenerate invalidate the consumer they changed. The button also reads "Generate Token" while no token exists. (Audit ADM-04f.)
|
|
8
|
+
|
|
3
9
|
## 1.2.0
|
|
4
10
|
|
|
5
11
|
### Added
|
package/TokenManager.tsx
CHANGED
|
@@ -78,7 +78,7 @@ const TokenManager = ({ id, hasToken, enabled, t }: Props): JSX.Element => {
|
|
|
78
78
|
subtype="secondary"
|
|
79
79
|
noMargin
|
|
80
80
|
loading={ isPendingRegenerate }
|
|
81
|
-
text={ <><FiRefreshCw /> { t('admin_api_consumers.token.regenerate', { ns: 'common' }) }</> }
|
|
81
|
+
text={ <><FiRefreshCw /> { t(hasToken ? 'admin_api_consumers.token.regenerate' : 'admin_api_consumers.token.generate', { ns: 'common' }) }</> }
|
|
82
82
|
onClick={ onRegenerate }
|
|
83
83
|
/>
|
|
84
84
|
|
package/package.json
CHANGED
package/services.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UseMutationResult, UseQueryResult, UseSuspenseQueryResult, useMutation, useQuery, useSuspenseQuery } from '@tanstack/react-query';
|
|
1
|
+
import { UseMutationResult, UseQueryResult, UseSuspenseQueryResult, useMutation, useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
|
|
2
2
|
import { apiClient } from '@autobusal/providers';
|
|
3
3
|
import { PaginationData } from '@autobusal/providers/types/pagination';
|
|
4
4
|
import { TableParamsData } from '@autobusal/providers/types/other';
|
|
@@ -106,8 +106,17 @@ export const useDeleteApiConsumer = (): UseMutationResult<void, Error, number, u
|
|
|
106
106
|
})
|
|
107
107
|
);
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
/*
|
|
110
|
+
* Claude - 2026-08-22 (audit finding ADM-04f): the token panel only showed
|
|
111
|
+
* a toggle/revoke/regenerate's effect after a full page reload - an admin
|
|
112
|
+
* could reasonably believe Revoke had failed. Each mutation now
|
|
113
|
+
* invalidates the consumer it changed, so the panel redraws from the
|
|
114
|
+
* server's answer immediately.
|
|
115
|
+
*/
|
|
116
|
+
export const useToggleApiConsumer = (): UseMutationResult<void, Error, { id: number, api: number }, unknown> => {
|
|
117
|
+
const client = useQueryClient();
|
|
118
|
+
|
|
119
|
+
return useMutation({
|
|
111
120
|
mutationKey: ['admin-api-consumers-toggle'],
|
|
112
121
|
mutationFn: async ({ id, api }: { id: number, api: number }) => (
|
|
113
122
|
await apiClient
|
|
@@ -115,12 +124,17 @@ export const useToggleApiConsumer = (): UseMutationResult<void, Error, { id: num
|
|
|
115
124
|
.then(response => (
|
|
116
125
|
response.data
|
|
117
126
|
))
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
);
|
|
127
|
+
),
|
|
128
|
+
onSuccess: (_, { id }): void => {
|
|
129
|
+
client.invalidateQueries({ queryKey: ['admin-api-consumers-manage', { id }] });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
};
|
|
121
133
|
|
|
122
|
-
export const useRevokeApiConsumerToken = (): UseMutationResult<void, Error, number, unknown> =>
|
|
123
|
-
|
|
134
|
+
export const useRevokeApiConsumerToken = (): UseMutationResult<void, Error, number, unknown> => {
|
|
135
|
+
const client = useQueryClient();
|
|
136
|
+
|
|
137
|
+
return useMutation({
|
|
124
138
|
mutationKey: ['admin-api-consumers-revoke'],
|
|
125
139
|
mutationFn: async (id: number) => (
|
|
126
140
|
await apiClient
|
|
@@ -128,12 +142,17 @@ export const useRevokeApiConsumerToken = (): UseMutationResult<void, Error, numb
|
|
|
128
142
|
.then(response => (
|
|
129
143
|
response.data
|
|
130
144
|
))
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
);
|
|
145
|
+
),
|
|
146
|
+
onSuccess: (_, id): void => {
|
|
147
|
+
client.invalidateQueries({ queryKey: ['admin-api-consumers-manage', { id }] });
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
};
|
|
134
151
|
|
|
135
|
-
export const useRegenerateApiConsumerToken = (): UseMutationResult<{ api_token: string }, Error, number, unknown> =>
|
|
136
|
-
|
|
152
|
+
export const useRegenerateApiConsumerToken = (): UseMutationResult<{ api_token: string }, Error, number, unknown> => {
|
|
153
|
+
const client = useQueryClient();
|
|
154
|
+
|
|
155
|
+
return useMutation({
|
|
137
156
|
mutationKey: ['admin-api-consumers-regenerate'],
|
|
138
157
|
mutationFn: async (id: number) => (
|
|
139
158
|
await apiClient
|
|
@@ -141,9 +160,12 @@ export const useRegenerateApiConsumerToken = (): UseMutationResult<{ api_token:
|
|
|
141
160
|
.then(response => (
|
|
142
161
|
response.data
|
|
143
162
|
))
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
);
|
|
163
|
+
),
|
|
164
|
+
onSuccess: (_, id): void => {
|
|
165
|
+
client.invalidateQueries({ queryKey: ['admin-api-consumers-manage', { id }] });
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
};
|
|
147
169
|
|
|
148
170
|
// Edited: Ferjolt Ozuni - Date: 2026-07-27
|
|
149
171
|
// Package 3 - API partner receivables reports + settlements
|