Skip to content

Commit

Permalink
Merge pull request #12 from mahajanmahesh935/CertificateService
Browse files Browse the repository at this point in the history
TASK: [##215331] :Added Certificate API calls
  • Loading branch information
paritshivani authored Mar 15, 2024
2 parents 9052296 + 92b4704 commit c6f2799
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/nulp_elite/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import UserPrefData from "pages/UserPrefData";
import { ChakraProvider } from "@chakra-ui/react";
import Profile from "pages/Profile";
import FAQPage from "pages/FAQPage";
import Certificate from "pages/Certificate";

function App() {
const [search, setSearch] = React.useState(true);
Expand Down Expand Up @@ -98,6 +99,11 @@ function App() {
path: "/search",
component: Search,
},
{
moduleName: "nulp_elite",
path: "/certificate",
component: Certificate,
},
];

// return(
Expand Down
95 changes: 95 additions & 0 deletions packages/nulp_elite/src/pages/Certificate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React, { useState, useEffect } from "react";
import { Box, Heading, Text, Button } from "@chakra-ui/react";
import URLSConfig from "../configs/urlConfig.json";
import {
validateCertificate,
fetchCertificatePreferences,
getBatchDetails,
} from "../services/cetificateService";
const Certificate = () => {
const [data, setData] = useState({});
const [bathId, setbatchId] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(null);
const [organisationIds, setOrganisationIds] = useState("");
useEffect(() => {
validateCertificatePage();
fetchCertificatePreferencesPage();
getBatchDetailsPage();
}, []);
const headers = {
"content-type": "Application/json",
};

const validateCertificatePage = async () => {
try {
const url =
"http://localhost:3000/learner/" +
URLSConfig.URLS.USER.VALIDATE_CERTIFICATE;
const response = await validateCertificate(url, data);
console.log(response.data.result);
setData(response.data.result);
} catch (error) {
setError(error.message);
}
};

const fetchCertificatePreferencesPage = async () => {
try {
const url =
"http://localhost:3000/learner/" +
URLSConfig.URLS.TENANT_PREFERENCE.READ;
const response = await fetchCertificatePreferences(url, data);
console.log(response.data.result);
setData(response.data.result);
} catch (error) {
setError(error.message);
}
};

const getBatchDetailsPage = async () => {
try {
const url =
"http://localhost:3000/learner/" +
URLSConfig.URLS.BATCH.GET_DETAILS +
"/" +
`${bathId}`;
const response = await getBatchDetails(url);
console.log(response.data.result);
setData(response.data.result);
} catch (error) {
setError(error.message);
}
};

const handleFilterChange = (field, value) => {
// Handle filter change logic here
};

return (
<Box textAlign="center" padding="10">
<Heading as="h1" size="2xl" marginBottom="4">
Welcome to Our Learning Portal Content
</Heading>
<Text fontSize="xl" marginBottom="8">
Enhance your knowledge and skills with our diverse range of courses and
content.
</Text>
<Button colorScheme="blue" size="lg" onClick={validateCertificate}>
Get User Data
</Button>

{isLoading && <p>Loading...</p>}
{error && <p>Error: {error}</p>}
{Object.keys(data).map((key) => (
<div key={key}>
<p>
{key}: {JSON.stringify(data[key])}
</p>
</div>
))}
</Box>
);
};

export default Certificate;
36 changes: 36 additions & 0 deletions packages/nulp_elite/src/services/cetificateService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { post, get } from "./RestClient.ts";

export const validateCertificate = async (url, data = {}, headers = {}) => {
const result = await post(url, data, {
headers,
});
if (result) {
return result;
} else {
return [];
}
};

export const fetchCertificatePreferences = async (
url,
data = {},
headers = {}
) => {
const result = await post(url, data, {
headers,
});
if (result) {
return result;
} else {
return [];
}
};

export const getBatchDetails = async (url, header = {}) => {
const result = await get(url, header);
if (result) {
return result;
} else {
return [];
}
};

0 comments on commit c6f2799

Please sign in to comment.