refactor(ui,tasks): enhance ActionButton to support submit/disabled states and expose isSubmitting
All checks were successful
Deploy Flowstate to VPS / deploy (push) Successful in 48s
All checks were successful
Deploy Flowstate to VPS / deploy (push) Successful in 48s
This commit is contained in:
parent
83dbe3a388
commit
1a8bed2d4f
3 changed files with 41 additions and 4 deletions
|
|
@ -50,6 +50,7 @@ export default function TaskForm({
|
||||||
form,
|
form,
|
||||||
error,
|
error,
|
||||||
isEditMode,
|
isEditMode,
|
||||||
|
isSubmitting,
|
||||||
todayString,
|
todayString,
|
||||||
updateField,
|
updateField,
|
||||||
handleAssigneeToggle,
|
handleAssigneeToggle,
|
||||||
|
|
@ -95,10 +96,20 @@ export default function TaskForm({
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center justify-end gap-3">
|
<div className="flex items-center justify-end gap-3">
|
||||||
<ActionButton href="/dashboard" variant="secondary" icon={X}>
|
<ActionButton
|
||||||
|
href="/dashboard"
|
||||||
|
variant="secondary"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
icon={X}
|
||||||
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
<ActionButton type="submit" variant="primary" icon={Check}>
|
<ActionButton
|
||||||
|
type="submit"
|
||||||
|
variant="primary"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
icon={Check}
|
||||||
|
>
|
||||||
{isEditMode ? "Save Changes" : "Create Task"}
|
{isEditMode ? "Save Changes" : "Create Task"}
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ export function useTaskForm(
|
||||||
defaultStatus?: TaskStatus,
|
defaultStatus?: TaskStatus,
|
||||||
) {
|
) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [, startTransition] = useTransition();
|
const [isPending, startTransition] = useTransition();
|
||||||
const isEditMode = mode === "edit" && initialData;
|
const isEditMode = mode === "edit" && initialData;
|
||||||
|
|
||||||
const todayString = new Date().toISOString().split("T")[0];
|
const todayString = new Date().toISOString().split("T")[0];
|
||||||
|
|
@ -121,6 +121,7 @@ export function useTaskForm(
|
||||||
form,
|
form,
|
||||||
error,
|
error,
|
||||||
isEditMode,
|
isEditMode,
|
||||||
|
isSubmitting: isPending,
|
||||||
todayString,
|
todayString,
|
||||||
updateField,
|
updateField,
|
||||||
handleAssigneeToggle,
|
handleAssigneeToggle,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,16 @@ import Link from "next/link";
|
||||||
import { ReactNode, ButtonHTMLAttributes } from "react";
|
import { ReactNode, ButtonHTMLAttributes } from "react";
|
||||||
import { LucideIcon } from "lucide-react";
|
import { LucideIcon } from "lucide-react";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Properties for the ActionButton component.
|
||||||
|
*
|
||||||
|
* @interface ActionButtonProps
|
||||||
|
* @extends {ButtonHTMLAttributes<HTMLButtonElement>}
|
||||||
|
* @property {string} [href] - Optional navigation target URL. Renders a Next.js Link component if defined.
|
||||||
|
* @property {"primary" | "secondary" | "danger"} [variant="primary"] - Visual style variant of the button.
|
||||||
|
* @property {ReactNode} children - Button label content or child nodes.
|
||||||
|
* @property {LucideIcon} [icon] - Optional Lucide icon component to display alongside the text label.
|
||||||
|
*/
|
||||||
interface ActionButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
interface ActionButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||||
href?: string;
|
href?: string;
|
||||||
variant?: "primary" | "secondary" | "danger";
|
variant?: "primary" | "secondary" | "danger";
|
||||||
|
|
@ -14,6 +24,12 @@ interface ActionButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||||
icon?: LucideIcon;
|
icon?: LucideIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a customizable button or link element styled with Tailwind CSS, supporting variants, icons, and disabled states.
|
||||||
|
*
|
||||||
|
* @param {ActionButtonProps} props - The component props.
|
||||||
|
* @returns {JSX.Element} The rendered button or link component.
|
||||||
|
*/
|
||||||
export function ActionButton({
|
export function ActionButton({
|
||||||
href,
|
href,
|
||||||
variant = "primary",
|
variant = "primary",
|
||||||
|
|
@ -50,7 +66,16 @@ export function ActionButton({
|
||||||
// If an href is passed -> Link button
|
// If an href is passed -> Link button
|
||||||
if (href) {
|
if (href) {
|
||||||
return (
|
return (
|
||||||
<Link href={href} className={combinedStyles}>
|
<Link
|
||||||
|
href={disabled ? "#" : href}
|
||||||
|
aria-disabled={disabled}
|
||||||
|
onClick={(e) => {
|
||||||
|
if (disabled) e.preventDefault();
|
||||||
|
}}
|
||||||
|
className={`${combinedStyles} ${
|
||||||
|
disabled ? "pointer-events-none opacity-50" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
{content}
|
{content}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue