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

Fixed export bugs on contact and discussion pages #158

Merged
merged 2 commits into from
Aug 3, 2023
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
11 changes: 11 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@testing-library/user-event": "^12.8.3",
"babel-eslint": "^10.1.0",
"bootstrap": "^4.6.0",
"export-to-csv": "^0.2.1",
"firebase": "^8.3.0",
"jquery": "^3.6.0",
"json-2-csv": "^3.10.2",
Expand Down
36 changes: 17 additions & 19 deletions src/components/pages/contacts/ContactsCsv.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import { json2csvAsync } from "json-2-csv";
import firebase from "firebase/app";
import "firebase/storage";
/*eslint-disable*/
import { ExportToCsv } from "export-to-csv";

async function generateCSV(users) {
// Create CSV String
users.sort((a, b) => a.name.localeCompare(b.name));
const filteredUsers = users.map(user => {
let obj = Object.assign({}, user);
delete obj.id;
delete obj.accountStatus;
return obj
});

filteredUsers.sort((a, b) => a.name.localeCompare(b.name));

const options = {
keys: [
{ field: "name", title: "Name" },
{ field: "email", title: "Email" },
{ field: "phone", title: "Phone" },
{ field: "validated", title: "Validated" },
],
headers: [ "Email", "Name", "Phone Number", "Is Admin", "Is Valid"],
showLabels: true,
showTitle: true,
title: "List Of Contacts",
};
const usersCSV = await json2csvAsync(users, options);

// Create CSV File
const storageRef = firebase.storage().ref();
const contactsCsvRef = storageRef.child("contacts.csv");
await contactsCsvRef.putString(usersCSV);

// Download CSV File
const ContactsURL = await contactsCsvRef.getDownloadURL();
window.open(ContactsURL);
const csvExporter = new ExportToCsv(options);
csvExporter.generateCsv(filteredUsers);
}

export default generateCSV;
38 changes: 21 additions & 17 deletions src/components/pages/discussion/DiscussionCSV.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
/* eslint-disable */
import { json2csvAsync } from "json-2-csv";
import firebase from "firebase/app";
import "firebase/storage";
import { ExportToCsv } from "export-to-csv";

async function generateCSV(posts, title) {
// Create CSV String
const filteredPosts = posts.map(user => {
let obj = Object.assign({}, user);
obj.username = obj.user.name;
delete obj.user;
delete obj.userRef;
delete obj.messageId;
return obj
});

const dateOptions = { month: "short", day: "numeric" };
const timeOptions = { hour: "numeric", minute: "numeric", hour12: true };
posts.forEach((post) => {
filteredPosts.forEach((post) => {
const x = post.timeSent.toDate();
const formattedDate = `${x.toLocaleDateString(
undefined,
dateOptions
)} at ${x.toLocaleTimeString(undefined, timeOptions)}`;
post.timeSent = formattedDate;
});

const options = {
keys: [
{ field: "user.name", title: "Name" },
{ field: "message", title: "Message" },
{ field: "timeSent", title: "time sent" },
],
headers: [ "Message", "Time Sent", "Name"],
showLabels: true,
showTitle: true,
title: "Discussion Log",
};
const postsCSV = await json2csvAsync(posts, options);

// Create CSV File
const storageRef = firebase.storage().ref();
const discussionCsvRef = storageRef.child(title + "Discussion.csv");
await discussionCsvRef.putString(postsCSV);
const csvExporter = new ExportToCsv(options);

// Download CSV File
const discussionURL = await discussionCsvRef.getDownloadURL();
window.open(discussionURL);
console.log(filteredPosts);
if(filteredPosts.length != 0){
csvExporter.generateCsv(filteredPosts);
}
}

export default generateCSV;
2 changes: 0 additions & 2 deletions src/components/pages/schedule/calendar/newCalendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ export default function NewCalendar() {
// eventClick={(info) => handleClick(info)}
// />
// );


// const updateMedia = () => {
// if (window.innerWidth > 900) {
// ReactDOM.render(
Expand Down
Loading