-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathuse-update-project-device.ts
More file actions
47 lines (42 loc) · 1.41 KB
/
use-update-project-device.ts
File metadata and controls
47 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Copyright (C) 2025 Intel Corporation
* SPDX-License-Identifier: Apache-2.0
*/
import { $api } from '@/api';
import { useProjectIdentifier } from '@/hooks';
import { getQueryKey } from '@/query-client';
import { useQueryClient } from '@tanstack/react-query';
export const useUpdateProjectDevice = () => {
const { projectId } = useProjectIdentifier();
const queryClient = useQueryClient();
// TODO: Replace with proper data type once the API is ready.
const mutation = $api.useMutation('put', '/api/v1/projects/{project_id}', {
meta: {
error: { notify: true },
},
});
const updateDevice = (device: string): void => {
mutation.mutate(
{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body: { device } as any,
params: { path: { project_id: projectId } },
},
{
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: getQueryKey([
'get',
'/api/v1/projects/{project_id}',
{ params: { path: { project_id: projectId } } },
]),
});
},
}
);
};
return {
mutate: updateDevice,
isPending: mutation.isPending,
};
};