diff --git a/src/components/Tabs/IdentificationTab.jsx b/src/components/Tabs/IdentificationTab.jsx index c2c5fe7f..bff37e74 100644 --- a/src/components/Tabs/IdentificationTab.jsx +++ b/src/components/Tabs/IdentificationTab.jsx @@ -23,7 +23,7 @@ import RequiredMark from "../FormComponents/RequiredMark"; import SelectInput from "../FormComponents/SelectInput"; import licenses from "../../utils/licenses"; import recordToDataCite from "../../utils/recordToDataCite"; -import { validateField, doiRegexp } from "../../utils/validate"; +import { validateField, validateDOI } from "../../utils/validate"; import { QuestionText, @@ -44,9 +44,8 @@ const IdentificationTab = ({ const { createDraftDoi, updateDraftDoi, deleteDraftDoi } = useContext(UserContext); const { language, region, userID } = useParams(); const regionInfo = regions[region]; - const doiIsValid = Boolean( - !record.datasetIdentifier || doiRegexp.test(record.datasetIdentifier) - ); + const doiIsValid =validateDOI(record.datasetIdentifier) + const languageUpperCase = language.toUpperCase(); const [doiGenerated, setDoiGenerated] = useState(false); const [doiErrorFlag, setDoiErrorFlag] = useState(false); @@ -89,13 +88,13 @@ const IdentificationTab = ({ }) .then(async (attributes) => { // Update the record object with datasetIdentifier and doiCreationStatus - updateRecord("datasetIdentifier")(attributes.doi); + updateRecord("datasetIdentifier")(`https://doi.org/${attributes.doi}`); updateRecord("doiCreationStatus")("draft"); // Create a new object with updated properties const updatedRecord = { ...record, - datasetIdentifier: attributes.doi, + datasetIdentifier: `https://doi.org/${attributes.doi}`, doiCreationStatus: "draft", }; @@ -134,8 +133,11 @@ const IdentificationTab = ({ delete mappedDataCiteObject.data.type; delete mappedDataCiteObject.data.attributes.prefix; + // Extract DOI from the full URL + const doi = record.datasetIdentifier.replace('https://doi.org/', ''); + const dataObject = { - doi: record.datasetIdentifier, + doi, data: mappedDataCiteObject, } @@ -161,7 +163,10 @@ const IdentificationTab = ({ setLoadingDoiDelete(true); try { - deleteDraftDoi(record.datasetIdentifier) + // Extract DOI from the full URL + const doi = record.datasetIdentifier.replace('https://doi.org/', ''); + + deleteDraftDoi(doi) .then((response) => response.data) .then(async (statusCode) => { if (statusCode === 204) { @@ -732,7 +737,7 @@ const IdentificationTab = ({ Loading... ) : ( - "Generate Draft DOI" + "Generate DOI" )} @@ -749,7 +754,7 @@ const IdentificationTab = ({ Loading... ) : ( - "Update Draft DOI" + "Update DOI" )} @@ -766,7 +771,7 @@ const IdentificationTab = ({ Loading... ) : ( - "Delete Draft DOI" + "Delete DOI" )} diff --git a/src/utils/validate.js b/src/utils/validate.js index b5124564..c8f51b30 100644 --- a/src/utils/validate.js +++ b/src/utils/validate.js @@ -16,7 +16,7 @@ function isValidHttpUrl(string) { return url.protocol === "http:" || url.protocol === "https:"; } - +export const validateDOI = (val) => !val || (doiRegexp.test(val) && isValidHttpUrl(val)); const validateLatitude = (num) => num >= -90 && num <= 90; const deepCompare = (obj1, obj2) => @@ -81,7 +81,7 @@ const validators = { }, }, datasetIdentifier: { - validation: (val) => !val || (doiRegexp.test(val) && isValidHttpUrl(val)), + validation: validateDOI, optional: true, tab: "dataID", error: {