enabled csv upload for team bulk invites (#9446)

pull/9466/head
Meet Patel 2023-06-11 15:06:59 +05:30 committed by GitHub
parent ed4a81e852
commit a21f0c46c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import { PaperclipIcon, UserIcon, Users } from "lucide-react";
import { Trans } from "next-i18next";
import { useMemo, useState } from "react";
import type { FormEvent } from "react";
import { Controller, useForm } from "react-hook-form";
import { classNames } from "@calcom/lib";
@ -50,6 +51,10 @@ export interface NewMemberForm {
type ModalMode = "INDIVIDUAL" | "BULK";
interface FileEvent<T = Element> extends FormEvent<T> {
target: EventTarget & T;
}
export default function MemberInvitationModal(props: MemberInvitationModalProps) {
const { t } = useLocale();
const trpcContext = trpc.useContext();
@ -90,6 +95,25 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)
);
};
const handleFileUpload = (e: FileEvent<HTMLInputElement>) => {
if (!e.target.files?.length) {
return;
}
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
const contents = e?.target?.result as string;
const values = contents?.split(",").map((email) => email.trim().toLocaleLowerCase());
newMemberFormMethods.setValue("emailOrUsername", values);
};
reader.readAsText(file);
}
};
return (
<Dialog
name="inviteModal"
@ -198,12 +222,20 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)
}}
/>
<Button
disabled
type="button"
color="secondary"
StartIcon={PaperclipIcon}
className="mt-3 justify-center stroke-2">
Upload a .csv file
<label htmlFor="bulkInvite">
Upload a .csv file
<input
id="bulkInvite"
type="file"
accept=".csv"
style={{ display: "none" }}
onChange={handleFileUpload}
/>
</label>
</Button>
</div>
)}