File size: 1,325 Bytes
68ed806
9ee6e3a
 
 
 
 
2bdad3e
8441328
565e3eb
be99f83
 
 
 
 
 
 
 
 
 
 
 
 
8441328
9ee6e3a
be99f83
 
9ee6e3a
 
 
 
c298fc4
 
acf53dd
7a2a8fe
c298fc4
be99f83
196c662
be99f83
8441328
be99f83
 
9ee6e3a
be99f83
 
 
 
 
 
 
 
2bdad3e
be99f83
 
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
48
49
50
51
52
53
54
import { useSetModalState } from '@/hooks/common-hooks';
import {
  useFetchFlowList,
  useFetchFlowTemplates,
  useSetFlow,
} from '@/hooks/flow-hooks';
import { useCallback } from 'react';
import { useNavigate } from 'umi';

export const useFetchDataOnMount = () => {
  const { data, loading } = useFetchFlowList();

  return { list: data, loading };
};

export const useSaveFlow = () => {
  const {
    visible: flowSettingVisible,
    hideModal: hideFlowSettingModal,
    showModal: showFileRenameModal,
  } = useSetModalState();
  const { loading, setFlow } = useSetFlow();
  const navigate = useNavigate();
  const { data: list } = useFetchFlowTemplates();

  const onFlowOk = useCallback(
    async (title: string, templateId: string) => {
      const templateItem = list.find((x) => x.id === templateId);

      let dsl = templateItem?.dsl;
      const ret = await setFlow({
        title,
        dsl,
        avatar: templateItem?.avatar,
      });

      if (ret?.code === 0) {
        hideFlowSettingModal();
        navigate(`/flow/${ret.data.id}`);
      }
    },
    [setFlow, hideFlowSettingModal, navigate, list],
  );

  return {
    flowSettingLoading: loading,
    initialFlowName: '',
    onFlowOk,
    flowSettingVisible,
    hideFlowSettingModal,
    showFlowSettingModal: showFileRenameModal,
  };
};