|
1 | 1 | import { |
2 | | - FieldValue, |
3 | 2 | UseCheckForErrors, |
4 | | - UseSaveValue, |
5 | 3 | UseToggleField, |
6 | 4 | UseTruncateText |
7 | 5 | } from '@/types'; |
8 | | -import axios from 'axios'; |
9 | | - |
10 | | - |
11 | | -// ------------------------------------------------ Internal Functions // |
12 | | -function buildResponseItem(item: object, name: string | undefined, value: FieldValue) { |
13 | | - const returnItem = { ...item }; |
14 | | - |
15 | | - if (name) { |
16 | | - returnItem[name] = value; |
17 | | - } |
18 | | - |
19 | | - return returnItem; |
20 | | -} |
21 | 6 |
|
22 | 7 |
|
23 | 8 | // ------------------------------------------------ Composables // |
@@ -62,50 +47,6 @@ const useCheckForErrors: UseCheckForErrors = (options) => { |
62 | 47 | }; |
63 | 48 | }; |
64 | 49 |
|
65 | | -const useSaveValue: UseSaveValue = async (options) => { |
66 | | - const { settings, emit, name, value } = options; |
67 | | - const submitData = buildResponseItem(settings.item as object, name, value); |
68 | | - |
69 | | - if (settings.doNotSave) { |
70 | | - emit('update', value); |
71 | | - return { |
72 | | - error: false, |
73 | | - value, |
74 | | - }; |
75 | | - } |
76 | | - |
77 | | - if (settings.apiRoute === '') { |
78 | | - throw new Error('If the "doNotSave" prop is false, the "apiRoute" prop is required.'); |
79 | | - } |
80 | | - |
81 | | - const response = await axios({ |
82 | | - data: submitData, |
83 | | - method: settings.method as string, |
84 | | - url: settings.apiRoute as string, |
85 | | - }) |
86 | | - .then((response) => { |
87 | | - emit('update', response); |
88 | | - settings.originalValue = value; |
89 | | - |
90 | | - return { |
91 | | - error: false, |
92 | | - showField: false, |
93 | | - }; |
94 | | - }) |
95 | | - .catch((error) => { |
96 | | - console.error('error', error); |
97 | | - |
98 | | - emit('error', error); |
99 | | - |
100 | | - return { |
101 | | - error: true, |
102 | | - showField: false, |
103 | | - }; |
104 | | - }); |
105 | | - |
106 | | - return response; |
107 | | -}; |
108 | | - |
109 | 50 | const useToggleField: UseToggleField = (options) => { |
110 | 51 | const { attrs, closeSiblings, fieldOnly, props, showField, timeOpened } = options; |
111 | 52 | let opened = timeOpened; |
@@ -137,7 +78,6 @@ const useTruncateText: UseTruncateText = (options) => { |
137 | 78 |
|
138 | 79 | export { |
139 | 80 | useCheckForErrors, |
140 | | - useSaveValue, |
141 | 81 | useToggleField, |
142 | 82 | useTruncateText, |
143 | 83 | }; |
0 commit comments