|
1 |
| -import type { ClientConfiguration, NewProject, UpdateProject, ViewProject } from '$features/projects/models'; |
| 1 | +import type { ClientConfiguration, NewProject, NotificationSettings, UpdateProject, ViewProject } from '$features/projects/models'; |
2 | 2 | import type { WebSocketMessageValue } from '$features/websockets/models';
|
3 | 3 |
|
4 | 4 | import { accessToken } from '$features/auth/index.svelte';
|
@@ -30,11 +30,14 @@ export const queryKeys = {
|
30 | 30 | deleteSlack: (id: string | undefined) => [...queryKeys.id(id), 'delete-slack'] as const,
|
31 | 31 | id: (id: string | undefined) => [...queryKeys.type, id] as const,
|
32 | 32 | ids: (ids: string[] | undefined) => [...queryKeys.type, ...(ids ?? [])] as const,
|
| 33 | + integrationNotificationSettings: (id: string | undefined, integration: string) => [...queryKeys.id(id), integration, 'notification-settings'] as const, |
33 | 34 | organization: (id: string | undefined) => [...queryKeys.type, 'organization', id] as const,
|
34 | 35 | postConfig: (id: string | undefined) => [...queryKeys.id(id), 'post-config'] as const,
|
35 | 36 | postProject: () => [...queryKeys.type, 'post-project'] as const,
|
36 | 37 | postPromotedTab: (id: string | undefined) => [...queryKeys.id(id), 'promote-tab'] as const,
|
37 | 38 | postSlack: (id: string | undefined) => [...queryKeys.id(id), 'post-slack'] as const,
|
| 39 | + putIntegrationNotificationSettings: (id: string | undefined, integration: string) => |
| 40 | + [...queryKeys.id(id), integration, 'put-notification-settings'] as const, |
38 | 41 | resetData: (id: string | undefined) => [...queryKeys.id(id), 'reset-data'] as const,
|
39 | 42 | type: ['Project'] as const
|
40 | 43 | };
|
@@ -91,6 +94,13 @@ export interface GetProjectConfigRequest {
|
91 | 94 | };
|
92 | 95 | }
|
93 | 96 |
|
| 97 | +export interface GetProjectIntegrationNotificationSettingsRequest { |
| 98 | + route: { |
| 99 | + id: string | undefined; |
| 100 | + integration: string; |
| 101 | + }; |
| 102 | +} |
| 103 | + |
94 | 104 | export interface GetProjectRequest {
|
95 | 105 | route: {
|
96 | 106 | id: string | undefined;
|
@@ -130,6 +140,13 @@ export interface PostSlackRequest {
|
130 | 140 | };
|
131 | 141 | }
|
132 | 142 |
|
| 143 | +export interface PutProjectIntegrationNotificationSettingsRequest { |
| 144 | + route: { |
| 145 | + id: string | undefined; |
| 146 | + integration: string; |
| 147 | + }; |
| 148 | +} |
| 149 | + |
133 | 150 | export interface ResetDataRequest {
|
134 | 151 | route: {
|
135 | 152 | id: string;
|
@@ -273,6 +290,21 @@ export function getProjectConfig(request: GetProjectConfigRequest) {
|
273 | 290 | }));
|
274 | 291 | }
|
275 | 292 |
|
| 293 | +export function getProjectIntegrationNotificationSettings(request: GetProjectIntegrationNotificationSettingsRequest) { |
| 294 | + return createQuery<NotificationSettings, ProblemDetails>(() => ({ |
| 295 | + enabled: () => !!accessToken.current && !!request.route.id, |
| 296 | + queryFn: async ({ signal }: { signal: AbortSignal }) => { |
| 297 | + const client = useFetchClient(); |
| 298 | + const response = await client.getJSON<NotificationSettings>(`projects/${request.route.id}/${request.route.integration}/notifications`, { |
| 299 | + signal |
| 300 | + }); |
| 301 | + |
| 302 | + return response.data!; |
| 303 | + }, |
| 304 | + queryKey: queryKeys.integrationNotificationSettings(request.route.id, request.route.integration) |
| 305 | + })); |
| 306 | +} |
| 307 | + |
276 | 308 | export function getProjectQuery(request: GetProjectRequest) {
|
277 | 309 | return createQuery<ViewProject, ProblemDetails>(() => ({
|
278 | 310 | enabled: () => !!accessToken.current && !!request.route.id,
|
@@ -371,6 +403,23 @@ export function postSlack(request: PostSlackRequest) {
|
371 | 403 | }));
|
372 | 404 | }
|
373 | 405 |
|
| 406 | +export function putProjectIntegrationNotificationSettings(request: PutProjectIntegrationNotificationSettingsRequest) { |
| 407 | + const queryClient = useQueryClient(); |
| 408 | + |
| 409 | + return createMutation<boolean, ProblemDetails, NotificationSettings>(() => ({ |
| 410 | + enabled: () => !!accessToken.current && !!request.route.id, |
| 411 | + mutationFn: async (settings: NotificationSettings) => { |
| 412 | + const client = useFetchClient(); |
| 413 | + const response = await client.put(`projects/${request.route.id}/${request.route.integration}/notifications`, settings); |
| 414 | + return response.ok; |
| 415 | + }, |
| 416 | + mutationKey: queryKeys.putIntegrationNotificationSettings(request.route.id, request.route.integration), |
| 417 | + onSuccess: () => { |
| 418 | + queryClient.invalidateQueries({ queryKey: queryKeys.integrationNotificationSettings(request.route.id, request.route.integration) }); |
| 419 | + } |
| 420 | + })); |
| 421 | +} |
| 422 | + |
374 | 423 | export function resetData(request: ResetDataRequest) {
|
375 | 424 | return createMutation<void, ProblemDetails, void>(() => ({
|
376 | 425 | enabled: () => !!accessToken.current && !!request.route.id,
|
|
0 commit comments