From 1094a5efa807aeaea6f6eeacf81f035f1e39416c Mon Sep 17 00:00:00 2001 From: kasturi Date: Mon, 30 Mar 2026 12:30:13 +0530 Subject: [PATCH] fix: connect Add License form to createCandidateLicense API --- .../admin/license/create/AddLicenseClient.jsx | 60 +++++++++++++++++-- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/src/app/admin/license/create/AddLicenseClient.jsx b/src/app/admin/license/create/AddLicenseClient.jsx index f4ba5b633..63542a528 100644 --- a/src/app/admin/license/create/AddLicenseClient.jsx +++ b/src/app/admin/license/create/AddLicenseClient.jsx @@ -22,7 +22,13 @@ SPDX-License-Identifier: GPL-2.0-only import React, { useState } from "react"; // Widgets -import { InputContainer, Button } from "@/components/Widgets"; +import { InputContainer, Button, Alert, Spinner } from "@/components/Widgets"; + +// Service +import { createCandidateLicense } from "@/services/licenses"; + +// Constants +import { initialMessage } from "@/constants/constants"; const AddLicensePage = () => { const options = [ @@ -30,6 +36,10 @@ const AddLicensePage = () => { { id: 2, value: "No" }, ]; + const [loading, setLoading] = useState(false); + const [showMessage, setShowMessage] = useState(false); + const [message, setMessage] = useState(initialMessage); + const [formData, setFormData] = useState({ active: "", checked: "", @@ -55,16 +65,54 @@ const AddLicensePage = () => { })); }; - const handleSubmit = (e) => { + const handleSubmit = async (e) => { e.preventDefault(); - // Submit formData via API here - console.log("Submitted:", formData); + setLoading(true); + try { + const res = await createCandidateLicense({ + shortName: formData.shortName, + fullName: formData.fullName, + text: formData.licenseText, + risk: formData.riskLevel, + licenseUrl: formData.url, + mergeRequest: false, + }); + setMessage({ type: "success", text: res.message || "License added successfully." }); + setFormData({ + active: "", + checked: "", + spdxCompatible: "", + shortName: "", + fullName: "", + licenseText: "", + textUpdatable: "", + detectorType: "", + url: "", + publicNotes: "", + conclusion: "", + reportedLicense: "", + riskLevel: "", + obligations: "", + }); + } catch (error) { + setMessage({ type: "danger", text: error.message || "Failed to add license." }); + } finally { + setLoading(false); + setShowMessage(true); + } }; return (
+ {showMessage && ( + + )}

Add License


@@ -236,8 +284,8 @@ const AddLicensePage = () => { Associated Obligations -