-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateLicenseKeys.js
More file actions
81 lines (74 loc) · 2.3 KB
/
GenerateLicenseKeys.js
File metadata and controls
81 lines (74 loc) · 2.3 KB
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
// LicenseGeneratorPage.js
import React, { useState, useEffect } from 'react';
import '../../Styles/adminlicensegenerator.css'; // Import your CSS file
const LicenseGeneratorPage = () => {
const [licenses, setLicenses] = useState([]);
useEffect(() => {
// Fetch licenses with null key from your server
const fetchLicenses = async () => {
try {
const response = await fetch('http://localhost:4001/license/generateKeys');
if (response.ok) {
const data = await response.json();
setLicenses(data);
} else {
console.error('Failed to fetch licenses');
}
} catch (error) {
console.error('Error during license fetch:', error);
}
};
fetchLicenses();
}, []);
const generateLicenseKey = async (licenseId) => {
try {
const response = await fetch(`http://localhost:4001/license/updateKey/${licenseId}`, {
method: 'PUT',
});
if (response.ok) {
// Refresh the licenses after generating a key
const updatedLicenses = await response.json();
setLicenses(updatedLicenses);
alert("license Key is generated.")
} else {
console.error('Failed to generate license key');
}
} catch (error) {
console.error('Error during key generation:', error);
}
};
return (
<div className="license-generator-container">
<h2>License Generator</h2>
{licenses.length > 0 ? (
<table>
<thead>
<tr>
<th>License ID</th>
<th>Product ID</th>
<th>User ID</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{licenses.map((license) => (
<tr key={license._id}>
<td>{license._id}</td>
<td>{license.product}</td>
<td>{license.user}</td>
<td>
<button onClick={() => generateLicenseKey(license._id)}>
Generate License Key
</button>
</td>
</tr>
))}
</tbody>
</table>
) : (
<p>No licenses available.</p>
)}
</div>
);
};
export default LicenseGeneratorPage;