Skip to content

Commit

Permalink
add chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
amanver45 committed Oct 27, 2024
1 parent ec071cc commit 7b02d8d
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 395 deletions.
10 changes: 10 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,19 @@

<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

<!-- Chatbot integration -->
<script>
window.embeddedChatbotConfig = {
chatbotId: "czMRnh_MIVTru6ZhdgwzV",
domain: "www.chatbase.co"
};
</script>
<script
src="https://www.chatbase.co/embed.min.js"
chatbotId="rRGhO-tiXZz89Yeg1wTKc"
domain="www.chatbase.co"
defer>
</script>
</body>
</html>
77 changes: 3 additions & 74 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,3 @@
import React, { useState, useEffect } from "react";
import { Routes, Route, Navigate } from "react-router-dom";
import { useLocation } from "react-router-dom";
import Navbar from "./components/Navbar/Navbar.js";
import Hom from "./pages/Home/Hom.js";
import Educ from "./components/Education/Educ.js";
import Quiz from "./components/Quiz/Quiz.js";
import Craft from "./components/Craft/Craft.js";
import Sef from "./components/Sef/Sef.js";
import Act from "./components/Act/Act.js";
import Login from "./components/Login/Login.js";
import Signup from "./components/Signup/Signup.js";
import ForgotPassword from "./components/ForgotPassword/ForgotPassword.js";
import Footer from "./components/Footer/Footer.js";
import About from "./pages/About/About.js";
import Loan from "./pages/Loan/Loan.js";
import Dashboard from "./pages/Dashboard/Dashboard.js";
import Contact from "./pages/Contact/Contact.js";
import Error from "./pages/Error/index.js";
import ContributorsPage from "./pages/Contributor/ContributorsPage.jsx";
import Preloader from "./pages/Preloader/Preloader.jsx";

function App() {
const location = useLocation();

// Preloader logic
const [isPreloaderVisible, setIsPreloaderVisible] = useState(true);

useEffect(() => {
const timer = setTimeout(() => {
setIsPreloaderVisible(false);
}, 5000); // Preloader visible for 5 seconds

return () => clearTimeout(timer);
}, []);

return (
<>
{isPreloaderVisible ? (
<Preloader />
) : (
<div>
{location.pathname !== "/page-not-found" && <Navbar />}
<main>
<Routes>
<Route path="/" element={<Hom />} />
<Route path="/loan" element={<Loan />} />
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/about" element={<About />} />
<Route path="/educ" element={<Educ />} />
<Route path="/sef" element={<Sef />} />
<Route path="/craft" element={<Craft />} />
<Route path="/quiz" element={<Quiz />} />
<Route path="/act" element={<Act />} />
<Route path="/login" element={<Login />} />
<Route path="/signup" element={<Signup />} />
<Route path="/forgot-password" element={<ForgotPassword />} />
<Route path="/contact" element={<Contact />} />
<Route path="/page-not-found" element={<Error />} />
<Route path="/contributors" element={<ContributorsPage />} />
<Route path="*" element={<Navigate to="/page-not-found" replace />} />
</Routes>
</main>
{(location.pathname !== "/login" &&
location.pathname.toLowerCase() !== "/signup" &&
location.pathname.toLowerCase() !== "/forgot-password" &&
location.pathname.toLowerCase() !== "/page-not-found") && <Footer />}
</div>
)}
</>
);
}

export default App;
version https://git-lfs.github.com/spec/v1
oid sha256:93e5d91e873a1b4849663b26117dcdcb49db06c9b71b89790d3f4b5e1b939f4a
size 3664
166 changes: 3 additions & 163 deletions frontend/src/pages/Loan/Loan.js
Original file line number Diff line number Diff line change
@@ -1,163 +1,3 @@
import React, { useState } from 'react';
import './Loan.css'; // Import your custom CSS file

const Loan = () => {
const [loanAmount, setLoanAmount] = useState('');
const [interestRate, setInterestRate] = useState('');
const [loanTerm, setLoanTerm] = useState('');
const [paymentFrequency, setPaymentFrequency] = useState('monthly');
const [calculationResult, setCalculationResult] = useState(null);

const calculateLoan = () => {
const principal = parseFloat(loanAmount);
const annualRate = parseFloat(interestRate) / 100;
const termInYears = parseFloat(loanTerm);

if (isNaN(principal) || isNaN(annualRate) || isNaN(termInYears)) {
alert('Please enter valid numbers for all fields.');
return;
}

// Determine the number of payments per year and the interest rate per payment based on frequency
let paymentsPerYear;
if (paymentFrequency === 'monthly') {
paymentsPerYear = 12;
} else if (paymentFrequency === 'biweekly') {
paymentsPerYear = 26;
} else {
paymentsPerYear = 52;
}

const ratePerPeriod = annualRate / paymentsPerYear;
const totalPayments = termInYears * paymentsPerYear;

// Calculate the payment per period using the amortization formula
const paymentPerPeriod = (principal * ratePerPeriod * Math.pow(1 + ratePerPeriod, totalPayments)) /
(Math.pow(1 + ratePerPeriod, totalPayments) - 1);

const totalPayment = paymentPerPeriod * totalPayments;
const totalInterest = totalPayment - principal;

setCalculationResult({
paymentPerPeriod: paymentPerPeriod.toFixed(2),
totalPayment: totalPayment.toFixed(2),
totalInterest: totalInterest.toFixed(2),
frequency: paymentFrequency.charAt(0).toUpperCase() + paymentFrequency.slice(1)
});
};

return (
<div className="loan-container" style={{marginTop: "50px", marginBottom: "50px", paddingTop: "30px", paddingBottom: "30px"} }>
<h1 className="loan-title">Understanding Loans and Grants</h1>

<div className="horizontal-cards">
<section className="loan-section">
<h2>What is a Loan?</h2>
<p>
A loan is a sum of money that is borrowed and is expected to be paid back with interest.
Loans can be secured (backed by collateral) or unsecured (not backed by collateral).
</p>
<a href="https://en.wikipedia.org/wiki/Loan" target="_blank" rel="noopener noreferrer">
<button className="loan-button">Learn More</button>
</a>
</section>

<section className="loan-section">
<h2>What is a Grant?</h2>
<p>
A grant is a financial award given by a government agency, organization, or individual for a specific purpose,
and it does not need to be paid back.
</p>
<a href="https://en.wikipedia.org/wiki/Grant_(law)" target='_blank' rel="noopener noreferrer">
<button className="loan-button">Learn More</button>
</a>
</section>

<section className="loan-section types-of-loans">
<h2>Types of Loans</h2>
<ul>
<li>Personal Loans</li>
<li>Student Loans</li>
<li>Mortgage Loans</li>
<li>Auto Loans</li>
</ul>
<a href="https://en.wikipedia.org/wiki/Loan#Types" target='_blank' rel="noopener noreferrer">
<button className="loan-button">View Details</button>
</a>
</section>
</div>

<section className="loan-section tips">
<h2>Tips for Applying for Loans and Grants</h2>
<ul>
<li>Check your credit score before applying.</li>
<li>Research various options to find the best terms.</li>
<li>Gather necessary documentation in advance.</li>
<li>Be clear about your purpose and how you plan to use the funds.</li>
</ul>
</section>

<section className="loan-calculator">
<h2>Loan Calculator</h2>
<form className="calculator-form" onSubmit={(e) => e.preventDefault()}>
<label htmlFor="loanAmount">
Loan Amount:
<input
id="loanAmount"
type="number"
value={loanAmount}
onChange={(e) => setLoanAmount(e.target.value)}
placeholder="Enter amount"
required
/>
</label>
<label htmlFor="interestRate">
Annual Interest Rate (%):
<input
id="interestRate"
type="number"
value={interestRate}
onChange={(e) => setInterestRate(e.target.value)}
placeholder="Enter rate"
required
/>
</label>
<label htmlFor="loanTerm">
Loan Term (years):
<input
id="loanTerm"
type="number"
value={loanTerm}
onChange={(e) => setLoanTerm(e.target.value)}
placeholder="Enter term"
required
/>
</label>
<label htmlFor="paymentFrequency">
Payment Frequency:
<select
id="paymentFrequency"
value={paymentFrequency}
onChange={(e) => setPaymentFrequency(e.target.value)}
>
<option value="monthly">Monthly</option>
<option value="biweekly">Bi-weekly</option>
<option value="weekly">Weekly</option>
</select>
</label>
<button onClick={calculateLoan} className="loan-button">Calculate</button>
</form>
{calculationResult && (
<div className="calculator-result">
<h3>Loan Summary:</h3>
<p>{calculationResult.frequency} Payment: ${calculationResult.paymentPerPeriod}</p>
<p>Total Payment: ${calculationResult.totalPayment}</p>
<p>Total Interest: ${calculationResult.totalInterest}</p>
</div>
)}
</section>
</div>
);
};

export default Loan;
version https://git-lfs.github.com/spec/v1
oid sha256:bf5322c2ecfbc917f57fe7ce3a5fa72907bbe7ad020f7498061e7e7c5a90efcc
size 7404
25 changes: 3 additions & 22 deletions frontend/src/pages/Preloader/Preloader.jsx
Git LFS file not shown
Loading

0 comments on commit 7b02d8d

Please sign in to comment.