Skip to content

Commit

Permalink
v0.6.1
Browse files Browse the repository at this point in the history
# Release Notes - TPET v0.6.1

## New Features

- User can hover to see the tips of each input

## Fix

- User can unselect the files
  • Loading branch information
chungchihhan authored Aug 9, 2024
1 parent 19df89b commit 4bb45bf
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 21 deletions.
19 changes: 18 additions & 1 deletion src/app/ui/attach-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ export default function AttachDropdown({ onSelect }: AttachDropdownProps) {
setIsOpen(!isOpen);
};

const handleSelect = (file: fileDataType) => {
const handleSelect = (file: fileDataType | null) => {
if (!file) {
setSelectedFiles([]);
onSelect([]);
setIsOpen(false);
return;
}
const alreadySelected = selectedFiles.some(
(selectedFile) => selectedFile.file_id === file.file_id
);
Expand Down Expand Up @@ -215,6 +221,17 @@ export default function AttachDropdown({ onSelect }: AttachDropdownProps) {
</tr>
</thead>
<tbody>
<tr
className="hover:bg-gray-200 cursor-pointer active:bg-gray-300"
onClick={() => handleSelect(null)}
>
<td
className="py-2 px-4 border-b border-gray-200 text-start"
colSpan={3}
>
No Selection
</td>
</tr>
{filteredOptions.map((option) => (
<tr
key={option.file_id}
Expand Down
26 changes: 26 additions & 0 deletions src/app/ui/help-tip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use client";
import { ReactNode, useState } from "react";

interface TooltipProps {
message: string;
children: ReactNode;
}

export default function Helptip({ message, children }: TooltipProps) {
const [isVisible, setIsVisible] = useState(false);

return (
<div
className="relative flex items-center hover:cursor-help"
onMouseEnter={() => setIsVisible(true)}
onMouseLeave={() => setIsVisible(false)}
>
{children}
{isVisible && (
<div className="absolute bottom-full transform bg-slate-200 text-slate-500 text-sm rounded-md shadow-xl p-2 whitespace-normal break-words z-50">
<p className="text-wrap min-w-64">{message}</p>
</div>
)}
</div>
);
}
25 changes: 21 additions & 4 deletions src/app/ui/select-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,18 @@ export default function SelectDropdown({
};

const handleSelect = (
file_id: string,
file_url: string,
file_name: string
file_id: string | null,
file_url: string | null,
file_name: string | null
) => {
if (!file_id || !file_url || !file_name) {
onSelect("", "");
setSelectedFileName(`Select a ${fileExtension} file`);
setIsOpen(false);
return;
}
onSelect(file_id, file_url);
console.log("Selected file:", file_id);
// console.log("Selected file:", file_id);
setSelectedFileName(file_name);
setIsOpen(false);
};
Expand Down Expand Up @@ -217,6 +223,17 @@ export default function SelectDropdown({
</tr>
</thead>
<tbody>
<tr
className="hover:bg-gray-200 cursor-pointer active:bg-gray-300"
onClick={() => handleSelect(null, null, null)}
>
<td
className="py-2 px-4 border-b border-gray-200 text-start"
colSpan={3}
>
No Selection
</td>
</tr>
{filteredOptions.map((option) => (
<tr
key={option.file_id}
Expand Down
72 changes: 56 additions & 16 deletions src/app/ui/send-email-form.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"use client";
import React, { useRef, useState, FormEvent } from "react";
import { submitForm } from "@/lib/actions";
import HelpTip from "@/app/ui/help-tip";
import SelectDropdown from "@/app/ui/select-dropdown";
import AttachDropdown from "./attach-dropdown";
import FileUpload from "@/app/ui/file-upload";
import IframePreview from "@/app/ui/iframe-preview";
import EmailInput from "@/app/ui/email-input";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { ChevronDown } from "lucide-react";
import { Info } from "lucide-react";

interface SubmitResponse {
status: string;
Expand All @@ -22,10 +23,10 @@ interface SubmitResponse {
export default function SendEmailForm() {
const ref = useRef<HTMLFormElement>(null);
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
const [selectedHtmlFile, setSelectedHtmlFile] = useState("");
const [selectedXlsxFile, setSelectedXlsxFile] = useState("");
const [htmlPreviewLink, setHtmlPreviewLink] = useState<string>("");
const [xlsxPreviewLink, setXlsxPreviewLink] = useState<string>("");
const [selectedHtmlFile, setSelectedHtmlFile] = useState<string | null>("");
const [selectedXlsxFile, setSelectedXlsxFile] = useState<string | null>("");
const [htmlPreviewLink, setHtmlPreviewLink] = useState<string | null>("");
const [xlsxPreviewLink, setXlsxPreviewLink] = useState<string | null>("");
const [errors, setErrors] = useState<{ [key: string]: string }>({});
const [showHtmlUpload, setShowHtmlUpload] = useState<boolean>(false);
const [showXlsxUpload, setShowXlsxUpload] = useState<boolean>(false);
Expand Down Expand Up @@ -105,7 +106,10 @@ export default function SendEmailForm() {
setIsSubmitting(false);
};

const handleHtmlSelect = (file_id: string, file_url: string) => {
const handleHtmlSelect = (
file_id: string | null,
file_url: string | null
) => {
setSelectedHtmlFile(file_id);
setHtmlPreviewLink(file_url);
};
Expand Down Expand Up @@ -188,8 +192,11 @@ export default function SendEmailForm() {
<p className="text-2xl font-bold py-2">Required</p>
<div className="rounded-md bg-neutral-100 p-4">
<div className="m-3">
<label className="mb-2 block text-sm font-medium">
<label className="mb-2 flex text-sm font-medium gap-2">
Subject of the email:
<HelpTip message="Enter the email subject that recipients will see.">
<Info size={16} color="gray" />
</HelpTip>
</label>
<input
id="subject"
Expand All @@ -206,8 +213,11 @@ export default function SendEmailForm() {
)}
</div>
<div className="m-3">
<label className="mb-2 block text-sm font-medium">
<label className="mb-2 flex text-sm font-medium gap-2">
Name of the sender:
<HelpTip message="Enter the sender's name as it will appear to recipients.">
<Info size={16} color="gray" />
</HelpTip>
</label>
<input
id="display_name"
Expand All @@ -224,8 +234,11 @@ export default function SendEmailForm() {
)}
</div>
<div className="m-3">
<label className="mb-2 block text-sm font-medium">
<label className="mb-2 flex text-sm font-medium gap-2">
Select your template file:
<HelpTip message="Choose or upload a .html file that contains the email content.">
<Info size={16} color="gray" />
</HelpTip>
</label>
<div className="flex items-center gap-2">
<SelectDropdown
Expand Down Expand Up @@ -312,8 +325,11 @@ export default function SendEmailForm() {
)}
</div>
<div className="m-3">
<label className="mb-2 block text-sm font-medium">
<label className="mb-2 flex text-sm font-medium gap-2">
Select your sheet file:
<HelpTip message="Choose or upload a .xlsx file containing the list of recipients.">
<Info size={16} color="gray" />
</HelpTip>
</label>
<div className="flex items-center gap-2">
<SelectDropdown
Expand Down Expand Up @@ -409,8 +425,11 @@ export default function SendEmailForm() {
<div className="rounded-md bg-neutral-100 p-4">
{/* Sender Local Part */}
<div className="m-3">
<label className="mb-2 block text-sm font-medium">
<label className="mb-2 flex text-sm font-medium gap-2">
Sender Local Part:
<HelpTip message="Enter the prefix for your email address (e.g., if you enter john.doe, the email will be [email protected]). This setting will affect the forwarding rules.">
<Info size={16} color="gray" />
</HelpTip>
</label>
<div className="flex items-center bg-neutral-300 rounded-md">
<input
Expand All @@ -432,32 +451,50 @@ export default function SendEmailForm() {
</div>
{/* Reply To */}
<div className="m-3">
<label className="mb-2 block text-sm font-medium">Reply To:</label>
<label className="mb-2 flex text-sm font-medium gap-2">
Reply To:
<HelpTip message="The email address where replies from recipients will be sent. You can set this to match the Sender Local Part or customize it.">
<Info size={16} color="gray" />
</HelpTip>
</label>
<EmailInput
allowMultiple={false}
onEmailsChange={handleReplyToEmailChange}
/>
</div>
{/* BCC */}
<div className="m-3">
<label className="mb-2 block text-sm font-medium">BCC:</label>
<label className="mb-2 flex text-sm font-medium gap-2">
BCC:
<HelpTip message="Add email addresses to send blind carbon copies.">
<Info size={16} color="gray" />
</HelpTip>
</label>
<EmailInput
allowMultiple={true}
onEmailsChange={handleBccEmailsChange}
/>
</div>
{/* CC */}
<div className="m-3">
<label className="mb-2 block text-sm font-medium">CC:</label>
<label className="mb-2 flex text-sm font-medium gap-2">
CC:
<HelpTip message="Add email addresses to send carbon copies. Recipients will see these addresses.">
<Info size={16} color="gray" />
</HelpTip>
</label>
<EmailInput
allowMultiple={true}
onEmailsChange={handleCcEmailsChange}
/>
</div>
{/* Attach files */}
<div className="m-3">
<label className="mb-2 block text-sm font-medium">
<label className="mb-2 flex text-sm font-medium gap-2">
Attach files:
<HelpTip message="Attach any files you want to include with the email. Note: It is recommended that the total size of attachments does not exceed 5MB.">
<Info size={16} color="gray" />
</HelpTip>
</label>
<div className="flex items-center gap-2">
<AttachDropdown onSelect={handleAttachSelect} />
Expand Down Expand Up @@ -495,8 +532,11 @@ export default function SendEmailForm() {
</div>
{/* Generate certificate */}
<div className="my-5 mx-3">
<label className="mb-2 block text-sm font-medium">
<label className="mb-2 flex text-sm font-medium gap-2">
Provide a certification of participation?
<HelpTip message="Select Yes or No if you want to provide a certification. Note: If you select Yes, the Excel file must include two columns: Name and Certificate Text.">
<Info size={16} color="gray" />
</HelpTip>
</label>
<div className="flex">
<div className="flex items-center me-4">
Expand Down

0 comments on commit 4bb45bf

Please sign in to comment.