implemented add data using spreadsheet functionality
This commit is contained in:
parent
645a89aa43
commit
7dc6aace7a
@ -37,6 +37,7 @@ const AddCampaign = () => {
|
|||||||
language: "",
|
language: "",
|
||||||
campaignType: "",
|
campaignType: "",
|
||||||
video: null,
|
video: null,
|
||||||
|
spreadSheet: null,
|
||||||
recipients: [{ name: "", phoneNumber: "" }],
|
recipients: [{ name: "", phoneNumber: "" }],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,17 +2,56 @@ import React from "react";
|
|||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import { CFormInput, CFormLabel, CCol, CRow } from "@coreui/react";
|
||||||
|
|
||||||
const ContactDetails = ({ props }) => {
|
const ContactDetails = ({ props }) => {
|
||||||
const { data, setData, handleView } = props;
|
const { data, setData, handleView } = props;
|
||||||
|
const [dataEntryMethod, setDataEntryMethod] = useState("manual");
|
||||||
|
const [csvData, setCsvData] = useState([]);
|
||||||
// const [recipients, setRecipients] = useState([{ name: "", phoneNumber: "" }]);
|
// const [recipients, setRecipients] = useState([{ name: "", phoneNumber: "" }]);
|
||||||
|
// console.log("data", data);
|
||||||
const addRecord = () => {
|
const addRecord = () => {
|
||||||
setData((prevData) => ({
|
setData((prevData) => ({
|
||||||
...prevData,
|
...prevData,
|
||||||
recipients: [...prevData.recipients, { name: "", phoneNumber: "" }],
|
recipients: [
|
||||||
|
...prevData.recipients,
|
||||||
|
{ name: "", phoneNumber: "", email: "" },
|
||||||
|
],
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSpreadSheet = (e) => {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (file) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
|
||||||
|
reader.onload = (event) => {
|
||||||
|
const csvData = event.target.result;
|
||||||
|
const rows = csvData.split("\n");
|
||||||
|
const extractedData = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < rows.length; i++) {
|
||||||
|
const row = rows[i].split(",");
|
||||||
|
if (row.length >= 2) {
|
||||||
|
const name = row[0].trim();
|
||||||
|
const email = row[1].trim();
|
||||||
|
if (name && email) {
|
||||||
|
extractedData.push({ name, email });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setCsvData(extractedData);
|
||||||
|
// console.log(csvData);
|
||||||
|
setData((prevData) => ({
|
||||||
|
...prevData,
|
||||||
|
recipients: extractedData,
|
||||||
|
spreadSheet: file.name,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
reader.readAsText(file);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const deleteRecipient = (index) => {
|
const deleteRecipient = (index) => {
|
||||||
const updatedRecipients = [...data.recipients];
|
const updatedRecipients = [...data.recipients];
|
||||||
updatedRecipients.splice(index, 1);
|
updatedRecipients.splice(index, 1);
|
||||||
@ -46,131 +85,193 @@ const ContactDetails = ({ props }) => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const recipientEmailChange = (e, index) => {
|
||||||
|
const updatedRecipients = [...data.recipients];
|
||||||
|
updatedRecipients[index] = {
|
||||||
|
...updatedRecipients[index],
|
||||||
|
email: e.target.value,
|
||||||
|
};
|
||||||
|
setData((prevData) => ({
|
||||||
|
...prevData,
|
||||||
|
recipients: updatedRecipients,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
if (
|
||||||
|
data?.recipients.every(
|
||||||
|
(recipient) =>
|
||||||
|
recipient.name !== "" &&
|
||||||
|
(data?.campaignType !== "email"
|
||||||
|
? recipient.phoneNumber !== ""
|
||||||
|
: recipient.email !== "")
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
handleView(3);
|
||||||
|
} else {
|
||||||
|
toast.error("Fill all contact details");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<div className="row">
|
<div>
|
||||||
<div className="col-12">
|
<div className="row">
|
||||||
<div
|
<div className="col-12">
|
||||||
className="
|
<div className="page-title-box d-flex align-items-center justify-content-between">
|
||||||
page-title-box
|
<div>
|
||||||
d-flex
|
<label>
|
||||||
align-items-center
|
Data Entry Method:
|
||||||
justify-content-between
|
<select
|
||||||
"
|
value={dataEntryMethod}
|
||||||
>
|
onChange={(e) => setDataEntryMethod(e.target.value)}
|
||||||
<div style={{ fontSize: "22px" }} className="fw-bold">
|
>
|
||||||
Contact Details
|
<option value="manual">Manually</option>
|
||||||
</div>
|
<option value="spreadsheet">Using Spreadsheet</option>
|
||||||
<div style={{ display: "flex", gap: "1rem" }}>
|
</select>
|
||||||
<h4 className="mb-0"></h4>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="page-title-right">
|
||||||
<div className="page-title-right">
|
<Button
|
||||||
<Button
|
variant="contained"
|
||||||
variant="contained"
|
color="secondary"
|
||||||
color="secondary"
|
style={{
|
||||||
style={{
|
fontWeight: "bold",
|
||||||
fontWeight: "bold",
|
marginBottom: "1rem",
|
||||||
marginBottom: "1rem",
|
textTransform: "capitalize",
|
||||||
textTransform: "capitalize",
|
marginRight: "5px",
|
||||||
marginRight: "5px",
|
}}
|
||||||
}}
|
onClick={() => handleView(1)}
|
||||||
onClick={() => handleView(1)}
|
>
|
||||||
>
|
Prev
|
||||||
Prev
|
</Button>
|
||||||
</Button>
|
<Button
|
||||||
<Button
|
variant="contained"
|
||||||
variant="contained"
|
color="secondary"
|
||||||
color="secondary"
|
style={{
|
||||||
style={{
|
fontWeight: "bold",
|
||||||
fontWeight: "bold",
|
marginBottom: "1rem",
|
||||||
marginBottom: "1rem",
|
textTransform: "capitalize",
|
||||||
textTransform: "capitalize",
|
}}
|
||||||
}}
|
onClick={handleSubmit}
|
||||||
onClick={() => {
|
>
|
||||||
if (
|
Next
|
||||||
data?.recipients.every(
|
</Button>
|
||||||
(recipient) =>
|
</div>
|
||||||
recipient.name !== "" && recipient.phoneNumber !== ""
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
handleView(3);
|
|
||||||
} else {
|
|
||||||
toast.error("Fill all contact details");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Next
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
<div className="row">
|
{dataEntryMethod === "manual" && (
|
||||||
<div className="col-sm-12 col-md-12 col-lg-12 my-1">
|
<div className="row">
|
||||||
<div className="card h-100">
|
<div className="col-md-12 my-1">
|
||||||
<div className="card-body px-5">
|
<div className="card h-100">
|
||||||
{data?.recipients.map((recipient, index) => {
|
<div className="card-body px-5">
|
||||||
return (
|
{data?.recipients.map((recipient, index) => {
|
||||||
<div className="mb-3 border p-3 rounded">
|
return (
|
||||||
<label
|
<div className="row mb-3 border p-3 rounded">
|
||||||
htmlFor="title"
|
<div className="col-md-6 d-flex align-items-center">
|
||||||
className="form-label d-flex justify-content-between"
|
<label htmlFor="title" className="form-label me-2">
|
||||||
|
Name
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
name={`name-${index}`}
|
||||||
|
value={recipient?.name}
|
||||||
|
onChange={(e) => recipientNameChange(e, index)}
|
||||||
|
maxLength="50"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6 d-flex align-items-center">
|
||||||
|
<label htmlFor="title" className="form-label me-2">
|
||||||
|
{data?.campaignType === "rcs" ||
|
||||||
|
data?.campaignType === "whatsapp"
|
||||||
|
? "Phone Number"
|
||||||
|
: "Email"}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type={
|
||||||
|
data?.campaignType === "rcs" ||
|
||||||
|
data?.campaignType === "whatsapp"
|
||||||
|
? "number"
|
||||||
|
: "email"
|
||||||
|
}
|
||||||
|
className="form-control"
|
||||||
|
id={`recipients-phone-number-${index}`}
|
||||||
|
maxLength="50"
|
||||||
|
name={`toPhoneNumber-${index}`}
|
||||||
|
value={
|
||||||
|
data?.campaignType === "rcs" ||
|
||||||
|
data?.campaignType === "whatsapp"
|
||||||
|
? recipient?.phoneNumber
|
||||||
|
: recipient?.email
|
||||||
|
}
|
||||||
|
onChange={(e) =>
|
||||||
|
data?.campaignType === "rcs" ||
|
||||||
|
data?.campaignType === "whatsapp"
|
||||||
|
? recipientNumberChange(e, index)
|
||||||
|
: recipientEmailChange(e, index)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{index !== 0 && (
|
||||||
|
<div className="col-12">
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
deleteRecipient(index);
|
||||||
|
}}
|
||||||
|
className="btn btn-danger btn-sm rounded-5 fw-bold mt-2"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<div className="col-md-12">
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
addRecord();
|
||||||
|
}}
|
||||||
|
className="btn btn-secondary"
|
||||||
>
|
>
|
||||||
<p>Name</p>
|
Add another record
|
||||||
|
</button>
|
||||||
{index === 0 ? null : (
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
deleteRecipient(index);
|
|
||||||
}}
|
|
||||||
className="btn btn-danger btn-smn rounded-5 fw-bold"
|
|
||||||
>
|
|
||||||
delete
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="form-control"
|
|
||||||
name={`name-${index}`}
|
|
||||||
value={recipient?.name}
|
|
||||||
onChange={(e) => recipientNameChange(e, index)}
|
|
||||||
maxLength="50"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<label htmlFor="title" className="form-label mt-2">
|
|
||||||
{data?.campaignType === "rcs" ||
|
|
||||||
data?.campaignType === "whatsapp" ? (
|
|
||||||
<p>Phone Number</p>
|
|
||||||
) : (
|
|
||||||
<p>Email</p>
|
|
||||||
)}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
className="form-control"
|
|
||||||
id="recipients-phone-number"
|
|
||||||
maxLength="50"
|
|
||||||
name={`toPhoneNumber-${index}`}
|
|
||||||
value={recipient?.phoneNumber}
|
|
||||||
onChange={(e) => recipientNumberChange(e, index)}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
</div>
|
||||||
})}
|
</div>
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
addRecord();
|
|
||||||
}}
|
|
||||||
className="btn btn-secondary"
|
|
||||||
>
|
|
||||||
Add another record
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
|
|
||||||
|
{dataEntryMethod === "spreadsheet" && (
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-md-12 my-1">
|
||||||
|
{/* Spreadsheet data entry form */}
|
||||||
|
<div className="card h-100">
|
||||||
|
<div className="card-body px-5">
|
||||||
|
<div className="row mb-3 border p-3 rounded">
|
||||||
|
<div className="mb-3">
|
||||||
|
<label htmlFor="title" className="form-label">
|
||||||
|
Upload Spreadsheet
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
className="form-control"
|
||||||
|
id="spreadsheet"
|
||||||
|
accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
|
||||||
|
onChange={(e) => handleSpreadSheet(e)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -68,15 +68,21 @@ const Preview = ({ props }) => {
|
|||||||
<td>{data?.campaignType}</td>
|
<td>{data?.campaignType}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col"> Video</th>
|
<th scope="col">
|
||||||
|
{data?.campaignType === "email" ? "Video" : "Spreadsheet"}
|
||||||
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<video
|
{data?.campaignType === "email" ? (
|
||||||
className="rounded"
|
<video
|
||||||
autoPlay={true}
|
className="rounded"
|
||||||
height={300}
|
autoPlay={true}
|
||||||
width={250}
|
height={300}
|
||||||
src={data?.video}
|
width={250}
|
||||||
></video>
|
src={data?.video}
|
||||||
|
></video>
|
||||||
|
) : (
|
||||||
|
<td>{data?.spreadSheet}</td>
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user