forked from YJU-OKURA/project_minori-next-deployment-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaterialForm.tsx
116 lines (108 loc) · 3.91 KB
/
MaterialForm.tsx
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import {ChangeEvent, useEffect, useRef, useState} from 'react';
import Image from 'next/image';
import postMaterial from '@/src/api/material/postMaterial';
import {FormProps} from '@/src/interfaces/navbar';
import icons from '@/public/svgs/navbar/prompt';
const MaterialForm = ({setIsOpen, editData}: FormProps) => {
const inputRef = useRef<HTMLInputElement>(null);
const [materialName, setMaterialName] = useState<string>('');
const [material, setMaterial] = useState<File>();
useEffect(() => {
if (editData) {
console.log(editData);
}
}, []);
const handleEnterName = (e: ChangeEvent<HTMLInputElement>) => {
setMaterialName(e.target.value);
};
const handleClickInput = () => {
inputRef.current?.click();
};
const handleChangeInput = (e: ChangeEvent<HTMLInputElement>) => {
const file = e.target.files;
if (file) {
setMaterial(file[0]);
// postMaterial(1, materialName, file[0]);
}
};
const handleClickButton = () => {
console.log(material, materialName);
if (material && materialName) {
postMaterial(4, materialName, material);
}
};
return (
<div>
<div className="fixed inset-0 z-10 flex items-center justify-center bg-black bg-opacity-50">
<div className=" bg-white rounded-lg w-2/5 h-3/4 py-10 box-border">
<div className="w-full h-full flex box-border px-10">
<div className="flex flex-col space-y-4 h-full w-full">
<div>
<div className="text-3xl font-bold">Make Prompt</div>
<div className="text-gray-500 py-1">
After you put in the file, you will get a prompt that says you
have learned the file.
</div>
</div>
<div className="py-1">
<div className="pb-2 font-semibold">Enter Prompt Name</div>
<input
type="text"
className="w-full border-2 p-2 rounded"
placeholder="prompt name"
onChange={handleEnterName}
/>
</div>
<div className="flex flex-col h-2/3">
<div className="pb-2 font-semibold">Enter Your File</div>
<div
className="w-full h-2/3 flex items-center justify-center bg-gray-50 text-center p-8 border-dashed border-2 border-gray-300"
onClick={handleClickInput}
>
<div>
<div className="pb-4">
<Image
src={icons.cloud}
alt="cloud"
width={60}
height={60}
className="m-auto "
/>
</div>
<div className="font-medium">
Drag & drop files or Browse
</div>
<div className="text-xs text-gray-400">
Supported formates: PDF, Word, PPT
</div>
<input
type="file"
className="hidden"
ref={inputRef}
onChange={handleChangeInput}
/>
</div>
</div>
</div>
<div className="flex justify-between text-sm font-medium">
<button
className="bg-gray-100 py-2 px-4 rounded"
onClick={() => setIsOpen(false)}
>
{'< '}Back
</button>
<button
className="bg-indigo-600 text-white py-2 px-3 rounded"
onClick={handleClickButton}
>
Make Prompt
</button>
</div>
</div>
</div>
</div>
</div>
</div>
);
};
export default MaterialForm;