-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from mahajanmahesh935/CertificateService
TASK: [##215331] :Added Certificate API calls
- Loading branch information
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 []; | ||
} | ||
}; |