ENCOA-37: Added the ability for users to download a list of the shown users
This commit is contained in:
36
src/utils/users.ts
Normal file
36
src/utils/users.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import {Group, User} from "@/interfaces/user";
|
||||
import {getUserCompanyName, USER_TYPE_LABELS} from "@/resources/user";
|
||||
import {capitalize} from "lodash";
|
||||
import moment from "moment";
|
||||
|
||||
export interface UserListRow {
|
||||
name: string;
|
||||
email: string;
|
||||
type: string;
|
||||
companyName: string;
|
||||
expiryDate: string;
|
||||
verified: string;
|
||||
country: string;
|
||||
phone: string;
|
||||
employmentPosition: string;
|
||||
gender: string;
|
||||
}
|
||||
|
||||
export const exportListToExcel = (rowUsers: User[], users: User[], groups: Group[]) => {
|
||||
const rows: UserListRow[] = rowUsers.map((user) => ({
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
type: USER_TYPE_LABELS[user.type],
|
||||
companyName: getUserCompanyName(user, users, groups),
|
||||
expiryDate: user.subscriptionExpirationDate ? moment(user.subscriptionExpirationDate).format("DD/MM/YYYY") : "Unlimited",
|
||||
country: user.demographicInformation?.country || "N/A",
|
||||
phone: user.demographicInformation?.phone || "N/A",
|
||||
employmentPosition: (user.type === "corporate" ? user.demographicInformation?.position : user.demographicInformation?.employment) || "N/A",
|
||||
gender: user.demographicInformation?.gender ? capitalize(user.demographicInformation.gender) : "N/A",
|
||||
verified: user.isVerified?.toString() || "FALSE",
|
||||
}));
|
||||
const header = "Name,Email,Type,Company Name,Expiry Date,Country,Phone,Employment/Position,Gender,Verification";
|
||||
const rowsString = rows.map((x) => Object.values(x).join(",")).join("\n");
|
||||
|
||||
return `${header}\n${rowsString}`;
|
||||
};
|
||||
Reference in New Issue
Block a user