feat(web): introduce templates
This commit is contained in:
15
packages/web/src/hooks/useAdminCreateTemplate.ee.js
Normal file
15
packages/web/src/hooks/useAdminCreateTemplate.ee.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useAdminCreateTemplate() {
|
||||
const mutation = useMutation({
|
||||
mutationFn: async ({ flowId, name }) => {
|
||||
const { data } = await api.post(`/v1/admin/templates`, { flowId, name });
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return mutation;
|
||||
}
|
||||
23
packages/web/src/hooks/useAdminDeleteTemplate.ee.js
Normal file
23
packages/web/src/hooks/useAdminDeleteTemplate.ee.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useAdminDeleteTemplate(templateId) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
const { data } = await api.delete(`/v1/admin/templates/${templateId}`);
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ['admin', 'templates'],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return mutation;
|
||||
}
|
||||
17
packages/web/src/hooks/useAdminTemplate.ee.js
Normal file
17
packages/web/src/hooks/useAdminTemplate.ee.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useAdminTemplate(templateId) {
|
||||
const query = useQuery({
|
||||
queryKey: ['admin', 'templates', templateId],
|
||||
queryFn: async ({ signal }) => {
|
||||
const { data } = await api.get(`/v1/admin/templates/${templateId}`, {
|
||||
signal,
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
||||
17
packages/web/src/hooks/useAdminTemplates.ee.js
Normal file
17
packages/web/src/hooks/useAdminTemplates.ee.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useAdminTemplates() {
|
||||
const query = useQuery({
|
||||
queryKey: ['admin', 'templates'],
|
||||
queryFn: async ({ signal }) => {
|
||||
const { data } = await api.get('/v1/admin/templates', {
|
||||
signal,
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useAdminUpdateConfig(appKey) {
|
||||
export default function useAdminUpdateConfig() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const query = useMutation({
|
||||
const mutation = useMutation({
|
||||
mutationFn: async (payload) => {
|
||||
const { data } = await api.patch('/v1/admin/config', payload);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ['automatisch', 'config'],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return query;
|
||||
return mutation;
|
||||
}
|
||||
|
||||
17
packages/web/src/hooks/useAdminUpdateTemplate.ee.js
Normal file
17
packages/web/src/hooks/useAdminUpdateTemplate.ee.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useAdminUpdateTemplate(templateId) {
|
||||
const mutation = useMutation({
|
||||
mutationFn: async ({ name }) => {
|
||||
const { data } = await api.patch(`/v1/admin/templates/${templateId}`, {
|
||||
name,
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return mutation;
|
||||
}
|
||||
@@ -5,19 +5,21 @@ import api from 'helpers/api';
|
||||
export default function useCreateFlow() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const query = useMutation({
|
||||
mutationFn: async () => {
|
||||
const { data } = await api.post('/v1/flows');
|
||||
const mutation = useMutation({
|
||||
mutationFn: async ({ templateId }) => {
|
||||
const { data } = await api.post('/v1/flows', null, {
|
||||
params: { templateId },
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ['flows'],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return query;
|
||||
return mutation;
|
||||
}
|
||||
|
||||
8
packages/web/src/hooks/useIsCurrentUserAdmin.js
Normal file
8
packages/web/src/hooks/useIsCurrentUserAdmin.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import userAbility from 'helpers/userAbility';
|
||||
import useCurrentUser from 'hooks/useCurrentUser';
|
||||
|
||||
export default function useIsCurrentUserAdmin() {
|
||||
const { data: currentUser } = useCurrentUser();
|
||||
|
||||
return currentUser?.data.role.isAdmin === true;
|
||||
}
|
||||
17
packages/web/src/hooks/useTemplates.ee.js
Normal file
17
packages/web/src/hooks/useTemplates.ee.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useTemplates() {
|
||||
const query = useQuery({
|
||||
queryKey: ['templates'],
|
||||
queryFn: async ({ signal }) => {
|
||||
const { data } = await api.get('/v1/templates', {
|
||||
signal,
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
||||
Reference in New Issue
Block a user