Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: [##215331] :Added Certificate API calls #12

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 [];
}
};
Loading