mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
chore(FE-195): adjust ConfirmationModal primaryButton and secondaryButton props
This commit is contained in:
@@ -1,30 +1,23 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { RefObject } from 'react';
|
import { MouseEventHandler, RefObject, useState } from 'react';
|
||||||
|
|
||||||
import { Icon } from '@iconify/react';
|
import { Icon } from '@iconify/react';
|
||||||
import Modal from '@/components/Modal';
|
import Modal from '@/components/Modal';
|
||||||
import Button from '@/components/Button';
|
import Button, { ButtonProps } from '@/components/Button';
|
||||||
|
|
||||||
import { cn } from '@/lib/helper';
|
import { cn } from '@/lib/helper';
|
||||||
import { Color } from '@/types/theme';
|
|
||||||
|
|
||||||
interface ConfirmationModalProps {
|
interface ConfirmationModalProps {
|
||||||
ref: RefObject<HTMLDialogElement | null>;
|
ref: RefObject<HTMLDialogElement | null>;
|
||||||
type?: 'info' | 'success' | 'error';
|
type?: 'info' | 'success' | 'error';
|
||||||
text?: string;
|
text?: string;
|
||||||
closeOnBackdrop?: boolean;
|
closeOnBackdrop?: boolean;
|
||||||
primaryButton?: {
|
primaryButton?: ButtonProps & {
|
||||||
text?: string;
|
text?: string;
|
||||||
color?: Color;
|
|
||||||
isLoading?: boolean;
|
|
||||||
onClick?: () => void;
|
|
||||||
};
|
};
|
||||||
secondaryButton?: {
|
secondaryButton?: ButtonProps & {
|
||||||
text?: string;
|
text?: string;
|
||||||
color?: Color;
|
|
||||||
isLoading?: boolean;
|
|
||||||
onClick?: () => void;
|
|
||||||
};
|
};
|
||||||
className?: {
|
className?: {
|
||||||
modal?: string;
|
modal?: string;
|
||||||
@@ -41,10 +34,22 @@ const ConfirmationModal = ({
|
|||||||
secondaryButton,
|
secondaryButton,
|
||||||
className,
|
className,
|
||||||
}: ConfirmationModalProps) => {
|
}: ConfirmationModalProps) => {
|
||||||
|
const [isPrimaryButtonLoading, setIsPrimaryButtonLoading] = useState(false);
|
||||||
|
|
||||||
const closeModalHandler = () => {
|
const closeModalHandler = () => {
|
||||||
ref.current?.close();
|
ref.current?.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const primaryButtonClickHandler: MouseEventHandler<
|
||||||
|
HTMLButtonElement
|
||||||
|
> = async (event) => {
|
||||||
|
setIsPrimaryButtonLoading(true);
|
||||||
|
|
||||||
|
await primaryButton?.onClick?.(event);
|
||||||
|
|
||||||
|
setIsPrimaryButtonLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal ref={ref} closeOnBackdrop={closeOnBackdrop} className={className}>
|
<Modal ref={ref} closeOnBackdrop={closeOnBackdrop} className={className}>
|
||||||
<div className='w-full flex flex-col gap-4'>
|
<div className='w-full flex flex-col gap-4'>
|
||||||
@@ -93,10 +98,15 @@ const ConfirmationModal = ({
|
|||||||
<div className='w-full flex flex-row gap-2'>
|
<div className='w-full flex flex-row gap-2'>
|
||||||
{secondaryButton && secondaryButton.text && (
|
{secondaryButton && secondaryButton.text && (
|
||||||
<Button
|
<Button
|
||||||
|
{...secondaryButton}
|
||||||
variant='ghost'
|
variant='ghost'
|
||||||
color={secondaryButton?.color ?? 'none'}
|
color={secondaryButton?.color}
|
||||||
isLoading={secondaryButton?.isLoading}
|
isLoading={secondaryButton?.isLoading}
|
||||||
disabled={secondaryButton?.isLoading}
|
disabled={
|
||||||
|
secondaryButton?.isLoading !== undefined
|
||||||
|
? secondaryButton?.isLoading
|
||||||
|
: isPrimaryButtonLoading
|
||||||
|
}
|
||||||
onClick={closeModalHandler}
|
onClick={closeModalHandler}
|
||||||
className='grow'
|
className='grow'
|
||||||
>
|
>
|
||||||
@@ -106,10 +116,19 @@ const ConfirmationModal = ({
|
|||||||
|
|
||||||
{primaryButton && primaryButton.text && (
|
{primaryButton && primaryButton.text && (
|
||||||
<Button
|
<Button
|
||||||
|
{...primaryButton}
|
||||||
color={primaryButton?.color ?? 'info'}
|
color={primaryButton?.color ?? 'info'}
|
||||||
onClick={primaryButton?.onClick}
|
onClick={primaryButtonClickHandler}
|
||||||
isLoading={primaryButton?.isLoading}
|
isLoading={
|
||||||
disabled={primaryButton?.isLoading}
|
primaryButton?.isLoading !== undefined
|
||||||
|
? primaryButton?.isLoading
|
||||||
|
: isPrimaryButtonLoading
|
||||||
|
}
|
||||||
|
disabled={
|
||||||
|
primaryButton?.isLoading !== undefined
|
||||||
|
? primaryButton?.isLoading
|
||||||
|
: isPrimaryButtonLoading
|
||||||
|
}
|
||||||
className='grow'
|
className='grow'
|
||||||
>
|
>
|
||||||
{primaryButton?.text ?? 'Ya'}
|
{primaryButton?.text ?? 'Ya'}
|
||||||
|
|||||||
Reference in New Issue
Block a user