@homefile/components-v2 2.11.4 → 2.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/forms/dynamicForm/fields/AIGridField.js +13 -6
- package/dist/interfaces/forms/dynamicForm/fields/GridField.interface.d.ts +2 -2
- package/package.json +1 -1
- package/src/components/forms/dynamicForm/fields/AIGridField.tsx +16 -8
- package/src/interfaces/forms/dynamicForm/fields/GridField.interface.ts +2 -2
|
@@ -4,8 +4,10 @@ import { Flex, IconButton, Text } from '@chakra-ui/react';
|
|
|
4
4
|
import { TextField, SingleImage, Plus } from '../../..';
|
|
5
5
|
import { fieldIcons } from '../../../../helpers';
|
|
6
6
|
import { colors } from '../../../../theme/colors';
|
|
7
|
+
import { useState } from 'react';
|
|
7
8
|
export const AIGridField = ({ children, onAISend, onRemove, onUpload, }) => {
|
|
8
9
|
var _a, _b, _c, _d, _e, _f;
|
|
10
|
+
const [file, setFile] = useState(undefined);
|
|
9
11
|
const { watch } = useFormContext();
|
|
10
12
|
const textChild = children === null || children === void 0 ? void 0 : children.find(({ type }) => type === 'text' || type === 'string');
|
|
11
13
|
const textProps = {
|
|
@@ -25,16 +27,21 @@ export const AIGridField = ({ children, onAISend, onRemove, onUpload, }) => {
|
|
|
25
27
|
? fieldIcons[imageField.icon]
|
|
26
28
|
: undefined,
|
|
27
29
|
};
|
|
28
|
-
const
|
|
30
|
+
const model = watch(String(textChild === null || textChild === void 0 ? void 0 : textChild.id));
|
|
31
|
+
const handleUpload = (files) => {
|
|
32
|
+
const file = files[0];
|
|
33
|
+
setFile(file);
|
|
34
|
+
onUpload === null || onUpload === void 0 ? void 0 : onUpload(files);
|
|
35
|
+
};
|
|
29
36
|
const handleAISend = () => {
|
|
30
37
|
const form = {};
|
|
31
|
-
if (
|
|
32
|
-
form.
|
|
38
|
+
if (model) {
|
|
39
|
+
form.model = model;
|
|
33
40
|
}
|
|
34
|
-
else if (
|
|
35
|
-
form.
|
|
41
|
+
else if (file) {
|
|
42
|
+
form.file = file;
|
|
36
43
|
}
|
|
37
44
|
onAISend === null || onAISend === void 0 ? void 0 : onAISend(form);
|
|
38
45
|
};
|
|
39
|
-
return (_jsxs(Flex, { align: "center", gap: "base", children: [_jsx(SingleImage, Object.assign({}, imageProps, { onUpload:
|
|
46
|
+
return (_jsxs(Flex, { align: "center", gap: "base", children: [_jsx(SingleImage, Object.assign({}, imageProps, { onUpload: handleUpload, onRemove: onRemove, value: imageField === null || imageField === void 0 ? void 0 : imageField.value })), _jsx(Text, { fontFamily: "secondary", textAlign: "center", children: "OR" }), _jsx(TextField, Object.assign({}, textProps)), _jsx(IconButton, { "aria-label": "Add new address line", variant: "iconOutlined", icon: _jsx(Plus, { size: 28, stroke: colors.blue[3] }), onClick: handleAISend, h: "input.md", disabled: !(model === null || model === void 0 ? void 0 : model.length) && !(imageField === null || imageField === void 0 ? void 0 : imageField.value) })] }));
|
|
40
47
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useFormContext } from 'react-hook-form'
|
|
2
2
|
import { Flex, IconButton, Text } from '@chakra-ui/react'
|
|
3
|
-
import { IconTypes, AIGridFieldI, AIFormI } from '@/interfaces'
|
|
3
|
+
import { IconTypes, AIGridFieldI, AIFormI, FolderFileI } from '@/interfaces'
|
|
4
4
|
import { TextField, SingleImage, Plus } from '@/components'
|
|
5
5
|
import { fieldIcons } from '@/helpers'
|
|
6
6
|
import { colors } from '@/theme/colors'
|
|
7
|
+
import { useState } from 'react'
|
|
7
8
|
|
|
8
9
|
export const AIGridField = ({
|
|
9
10
|
children,
|
|
@@ -11,6 +12,7 @@ export const AIGridField = ({
|
|
|
11
12
|
onRemove,
|
|
12
13
|
onUpload,
|
|
13
14
|
}: AIGridFieldI) => {
|
|
15
|
+
const [file, setFile] = useState<FolderFileI | undefined>(undefined)
|
|
14
16
|
const { watch } = useFormContext()
|
|
15
17
|
|
|
16
18
|
const textChild = children?.find(
|
|
@@ -37,15 +39,21 @@ export const AIGridField = ({
|
|
|
37
39
|
: undefined,
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
const
|
|
42
|
+
const model = watch(String(textChild?.id))
|
|
43
|
+
|
|
44
|
+
const handleUpload = (files: FolderFileI[]) => {
|
|
45
|
+
const file = files[0]
|
|
46
|
+
setFile(file)
|
|
47
|
+
onUpload?.(files)
|
|
48
|
+
}
|
|
41
49
|
|
|
42
50
|
const handleAISend = () => {
|
|
43
51
|
const form: AIFormI = {}
|
|
44
52
|
|
|
45
|
-
if (
|
|
46
|
-
form.
|
|
47
|
-
} else if (
|
|
48
|
-
form.
|
|
53
|
+
if (model) {
|
|
54
|
+
form.model = model
|
|
55
|
+
} else if (file) {
|
|
56
|
+
form.file = file
|
|
49
57
|
}
|
|
50
58
|
onAISend?.(form)
|
|
51
59
|
}
|
|
@@ -54,7 +62,7 @@ export const AIGridField = ({
|
|
|
54
62
|
<Flex align="center" gap="base">
|
|
55
63
|
<SingleImage
|
|
56
64
|
{...imageProps}
|
|
57
|
-
onUpload={
|
|
65
|
+
onUpload={handleUpload}
|
|
58
66
|
onRemove={onRemove}
|
|
59
67
|
value={imageField?.value as string}
|
|
60
68
|
/>
|
|
@@ -68,7 +76,7 @@ export const AIGridField = ({
|
|
|
68
76
|
icon={<Plus size={28} stroke={colors.blue[3]} />}
|
|
69
77
|
onClick={handleAISend}
|
|
70
78
|
h="input.md"
|
|
71
|
-
disabled={!
|
|
79
|
+
disabled={!model?.length && !imageField?.value}
|
|
72
80
|
/>
|
|
73
81
|
</Flex>
|
|
74
82
|
)
|