Skip to content

Commit

Permalink
Merge pull request #9 from Newspaper-Advertisement-Analyzer/develop
Browse files Browse the repository at this point in the history
Deploy Frontend
  • Loading branch information
Chanuka-ChandraYapa authored Oct 23, 2023
2 parents c258b2f + e94080e commit d87a3a9
Show file tree
Hide file tree
Showing 53 changed files with 2,014 additions and 791 deletions.
6 changes: 0 additions & 6 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,3 @@
**If your issue was not created using the app above, it will be closed immediately.**
-->

<!--
Love Creative Tim? Do you need Angular, React, Vuejs or HTML? You can visit:
👉 https://www.creative-tim.com/bundles
👉 https://www.creative-tim.com
-->
52 changes: 52 additions & 0 deletions src/api/ManageUser/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import axios from "axios";
import baseURL from "config";

// Function to delete a user
export async function deleteUser(userId) {
try {
const response = await axios.post(`${baseURL}/delete-user`, { user_ID: userId });
if (response.status === 200) {
console.log(response.data.message); // Assuming the response has a message field
} else {
console.error("Failed to delete user:", response.statusText);
}
} catch (error) {
console.error("Error deleting user:", error);
throw error;
}
}

// Function to edit user details
export async function editUser(userId, updatedData) {
try {
const response = await axios.post(`${baseURL}/updateUser`, {
userId: userId,
fullName: updatedData.fullName,
mobile: updatedData.contactNumber,
profession: updatedData.profession,
});
if (response.status === 200) {
console.log(response.data.message); // Assuming the response has a message field
} else {
console.error("Failed to edit user:", response.statusText);
}
} catch (error) {
console.error("Error editing user:", error);
throw error;
}
}

// Function to get the list of users
export async function getUserList() {
try {
const response = await axios.get(`${baseURL}/getAllUsers`);
if (response.status === 200) {
return response.data;
} else {
console.error("Failed to fetch user list:", response.statusText);
}
} catch (error) {
console.error("Error fetching user list:", error);
throw error;
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import baseURL from "config";

export async function sendUrlToBackend(inputUrl) {
export async function sendUrlToBackend(inputUrl, publish) {
try {
const response = await fetch(`${baseURL}/sendurl`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ url: inputUrl }),
body: JSON.stringify({ url: inputUrl, publish: publish }),
});

if (!response.ok) {
Expand Down
13 changes: 13 additions & 0 deletions src/api/graphViewer/prediction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import axios from "axios";
import baseURL from "config";

// Function to fetch data from the backend
export async function getPriceFluct() {
try {
const response = await axios.get(`${baseURL}/priceFluctuationData`); // Adjust the endpoint URL
return response.data;
} catch (error) {
console.error("Error fetching data from the backend:", error);
throw error;
}
}
12 changes: 12 additions & 0 deletions src/api/pendingAdvertisement/pendingAdvertisemnet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from "axios";
import baseURL from "config";

export async function fetchPendingAdvertisements() {
try {
const response = await axios.get(`${baseURL}/pendingAdvertisements`); // Adjust the endpoint URL
return response.data;
} catch (error) {
console.error("Error fetching pending advertisements:", error);
throw error;
}
}
46 changes: 34 additions & 12 deletions src/api/report/getReports.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
import axios from "axios";
import baseURL from "config";

// Function to fetch a saved PDF report from the backend
export async function getReportPdf(reportId) {
// Function to delete a user
export async function deleteUser(userId) {
try {
const response = await axios.get(`${baseURL}/view-pdf?ReportID=${reportId}`, {
responseType: "blob", // Specify the response type as a blob
});
const response = await axios.delete(`${baseURL}/users/${userId}`);
if (response.status === 200) {
console.log(`User with ID ${userId} has been deleted`);
} else {
console.error("Failed to delete user:", response.statusText);
}
} catch (error) {
console.error("Error deleting user:", error);
throw error;
}
}

// Function to edit user details
export async function editUser(userId, updatedData) {
try {
const response = await axios.put(`${baseURL}/users/${userId}`, updatedData);
if (response.status === 200) {
// Create a blob URL for the PDF data
const blob = new Blob([response.data], { type: "application/pdf" });
const url = window.URL.createObjectURL(blob);
console.log(`User with ID ${userId} has been updated`);
} else {
console.error("Failed to edit user:", response.statusText);
}
} catch (error) {
console.error("Error editing user:", error);
throw error;
}
}

// Open the PDF in a new tab
window.open(url, "_blank");
// Function to get the list of users
export async function getUserList() {
try {
const response = await axios.get(`${baseURL}/users`);
if (response.status === 200) {
return response.data;
} else {
console.error("Failed to fetch PDF report:", response.statusText);
console.error("Failed to fetch user list:", response.statusText);
}
} catch (error) {
console.error("Error fetching PDF report:", error);
console.error("Error fetching user list:", error);
throw error;
}
}
13 changes: 13 additions & 0 deletions src/api/submitAdvertisement/submitAdvertisement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import axios from "axios";
import baseURL from "config";

export async function submitAdvertisement(formData) {
console.log("submitAdvertisement formData:", formData);
try {
const response = await axios.post(`${baseURL}/submitAdvertisement`, formData); // Adjust the endpoint URL
return response.data;
} catch (error) {
console.error("Error submitting advertisement:", error);
throw error;
}
}
30 changes: 30 additions & 0 deletions src/api/updateUser/updateUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,33 @@ export async function updateUser(userData) {
throw error;
}
}

export async function updateProfilePicture(url, userId) {
try {
const response = await axios.post(`${baseURL}/updateProfilePicture`, { url, userId }); // Adjust the endpoint URL
console.log(response.data);
return response.data;
} catch (error) {
console.error("Error updating user data on the backend:", error);
throw error;
}
}

export async function updateLastSeen(userid) {
try {
const last_seen = Date.now(); // Obtain the timestamp
const date = new Date(last_seen); // Convert the timestamp to a Date object
const lastSeenDate = date.toLocaleDateString(); // Obtain the date in a locale-specific format
const lastSeenTime = date.toLocaleTimeString(); // Obtain the time in a locale-specific format
const lastSeenDateTime = `${lastSeenDate} ${lastSeenTime}`; // Combine the date and time
console.log(userid, lastSeenDateTime);
const response = await axios.post(`${baseURL}/updateLastSeen`, {
last_seen: lastSeenDateTime,
userId: userid,
});
return response.data;
} catch (error) {
console.error("Error updating user data on the backend:", error);
throw error;
}
}
Binary file added src/assets/images/newsback.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/examples/Cards/InfoCards/ProfileInfoCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import colors from "assets/theme/base/colors";
import typography from "assets/theme/base/typography";
import UpdateInfoModal from "./updateInfo";
import { useState } from "react";
import MDAlert from "components/MDAlert";

function ProfileInfoCard({ title, description, info, social, action, shadow }) {
const labels = [];
Expand Down Expand Up @@ -88,6 +89,7 @@ function ProfileInfoCard({ title, description, info, social, action, shadow }) {
));

const [isModalOpen, setIsModalOpen] = useState(false);
const [isPasswordChanged, setIsPasswordChanged] = useState(false);

const handleOpenModal = () => {
setIsModalOpen(true);
Expand All @@ -105,6 +107,11 @@ function ProfileInfoCard({ title, description, info, social, action, shadow }) {

return (
<Card sx={{ height: "100%", boxShadow: !shadow && "none" }}>
{isPasswordChanged && (
<MDAlert color="warning" dismissible>
Your password have been changed
</MDAlert>
)}
<MDBox display="flex" justifyContent="space-between" alignItems="center" pt={2} px={2}>
<MDTypography variant="h6" fontWeight="medium" textTransform="capitalize">
{title}
Expand All @@ -119,6 +126,7 @@ function ProfileInfoCard({ title, description, info, social, action, shadow }) {
onClose={handleCloseModal}
onSave={handleSaveInfo}
initialValues={updatedInfo} // Pass the current info data as initialValues
setChangePassword={setIsPasswordChanged}
/>
</MDBox>
<MDBox p={2}>
Expand Down
39 changes: 34 additions & 5 deletions src/examples/Cards/InfoCards/ProfileInfoCard/updateInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import MDButton from "components/MDButton";
import { updateUser } from "api/updateUser/updateUser";
import { useUser } from "utils/userContext";

function UpdateInfoModal({ open, onClose, onSave, initialValues }) {
function UpdateInfoModal({ open, onClose, onSave, initialValues, setChangePassword }) {
const [formData, setFormData] = useState(initialValues);
// const [changePassword, setChangePassword] = useState(false); // State to hold the change password checkbox value
const { user } = useUser();

const handleInputChange = (e) => {
Expand All @@ -24,13 +25,23 @@ function UpdateInfoModal({ open, onClose, onSave, initialValues }) {
};

const handleSave = async () => {
onSave(formData);
// eslint-disable-next-line no-unused-vars
const { password, ...formDataToSave } = formData;
onSave(formDataToSave);

try {
const userId = user.user_ID; // Extract the user ID from the form data
const { fullName, mobile, profession, location } = formData;
const { fullName, mobile, profession, location, password } = formData;
console.log(formData);
const userData = { fullName, mobile, profession, location, userId };
await updateUser(userData); // Call the updateUser API function
const userData = { fullName, mobile, profession, location, password, userId };
const response = await updateUser(userData); // Call the updateUser API function

// Check if the password was updated
if (response && response.password_updated) {
setChangePassword(true); // Reset the change password checkbox
// You can use a state or a notification library here to show the message to the user
console.log("Password has been updated.");
}

onClose(); // Close the modal after the update is successful
} catch (error) {
Expand Down Expand Up @@ -93,6 +104,23 @@ function UpdateInfoModal({ open, onClose, onSave, initialValues }) {
{/* Add more fields as needed */}
</form>
</Grid>
<Grid item xs={12}>
<MDTypography variant="h6" fontWeight="medium">
Change Account Password
</MDTypography>
</Grid>
<Grid item xs={12}>
<form>
<MDInput
type="password"
label="New Password"
name="password"
value={formData.password}
onChange={handleInputChange}
/>
<div style={{ marginBottom: "2%" }}></div>
</form>
</Grid>
<Grid item xs={12} style={{ display: "flex", justifyContent: "flex-end" }}>
<MDButton color="primary" onClick={handleSave}>
Save
Expand All @@ -114,6 +142,7 @@ UpdateInfoModal.propTypes = {
onClose: PropTypes.func.isRequired,
onSave: PropTypes.func.isRequired,
initialValues: PropTypes.object.isRequired,
setChangePassword: PropTypes.func.isRequired,
};

export default UpdateInfoModal;
Loading

0 comments on commit d87a3a9

Please sign in to comment.