File size: 5,497 Bytes
4fb0c68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import Sidebar from './OCRSidebar';
import Header from './OCRHeader';

const ConfigForm = () => {
    const [config, setConfig] = useState({
        MONGO_DETAILS: '',
        MongoDB_NAME: '',
        COLLECTION_NAMES: '',
        SECRET_KEY: '',
        ALGORITHM: '',
        ACCESS_TOKEN_EXPIRE_MINUTES: 0
    });

    useEffect(() => {
        axios.get('http://localhost:8000/config')
            .then(response => setConfig(response.data))
            .catch(error => console.error('Error fetching config:', error));
    }, []);

    const handleChange = (e) => {
        const { name, value } = e.target;
        setConfig({
            ...config,
            [name]: value
        });
    };

    const handleSubmit = (e) => {
        e.preventDefault();
        axios.patch('http://localhost:8000/config', config)
            .then(response => {
                setConfig(response.data);
                alert('Config updated successfully!');
            })
            .catch(error => console.error('Error updating config:', error));
    };

    return (
        <div className="min-h-screen bg-gray-100 flex">
            <Sidebar />
            <div className="flex-1 p-6">
                <Header />
                <div className="bg-white p-6 rounded-lg shadow-lg w-full max-w-4xl mx-auto">
                    <h2 className="text-2xl font-bold mb-6">Manage Credentials</h2>
                    <form className="space-y-4" onSubmit={handleSubmit}>
                        <div>
                            <label className="block text-gray-700">ERP details</label>
                            <input
                                type="text"
                                name="MONGO_DETAILS"
                                value={config.MONGO_DETAILS}
                                onChange={handleChange}
                                className="w-full px-4 py-2 border rounded-md"
                            />
                        </div>
                        <div>
                            <label className="block text-gray-700">Client ID</label>
                            <input
                                type="text"
                                name="MongoDB_NAME"
                                value={config.MongoDB_NAME}
                                onChange={handleChange}
                                className="w-full px-4 py-2 border rounded-md"
                            />
                        </div>
                        <div>
                            <label className="block text-gray-700">Client Secret</label>
                            <input
                                type="text"
                                name="COLLECTION_NAMES"
                                value={config.COLLECTION_NAMES}
                                onChange={handleChange}
                                className="w-full px-4 py-2 border rounded-md"
                            />
                        </div>
                        <div>
                            <label className="block text-gray-700">Username</label>
                            <input
                                type="text"
                                name="SECRET_KEY"
                                value={config.SECRET_KEY}
                                onChange={handleChange}
                                className="w-full px-4 py-2 border rounded-md"
                            />
                        </div>
                        <div>
                            <label className="block text-gray-700">Password</label>
                            <input
                                type="password"
                                name="ALGORITHM"
                                value={config.ALGORITHM}
                                onChange={handleChange}
                                className="w-full px-4 py-2 border rounded-md"
                            />
                        </div>
                        <div>
                            <label className="block text-gray-700">Company Code</label>
                            <input
                                type="text"
                                name="ACCESS_TOKEN_EXPIRE_MINUTES"
                                value={config.ACCESS_TOKEN_EXPIRE_MINUTES}
                                onChange={handleChange}
                                className="w-full px-4 py-2 border rounded-md"
                            />
                        </div>
                        <div>
                            <label className="block text-gray-700">API Key (Optional)</label>
                            <input
                                type="text"
                                name="API_KEY"
                                value={config.API_KEY}
                                onChange={handleChange}
                                className="w-full px-4 py-2 border rounded-md"
                            />
                        </div>
                        <button
                            type="submit"
                            className="w-full bg-blue-500 text-white px-4 py-2 rounded-md"
                        >
                            Save Credentials
                        </button>
                    </form>
                </div>
            </div>
        </div>
    );
};

export default ConfigForm;