-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat]: Create RejectSelectedModal Component (#3233)
* feat: Create RejectSelectedModal component for rejecting selected entries with a reason * fix:Cspell * refact: coderabbitai
- Loading branch information
1 parent
e64da11
commit c3afbd1
Showing
7 changed files
with
157 additions
and
29 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { clsxm } from "@/app/utils"; | ||
import { Modal } from "@/lib/components"; | ||
import { useState } from "react"; | ||
export interface IRejectSelectedModalProps { | ||
isOpen: boolean; | ||
closeModal: () => void; | ||
onReject: (reason: string) => void; | ||
minReasonLength?: number; | ||
maxReasonLength?: number; | ||
} | ||
export function RejectSelectedModal({ isOpen, closeModal, maxReasonLength, onReject, minReasonLength }: IRejectSelectedModalProps) { | ||
const [isSubmitting, setIsSubmitting] = useState(false); | ||
const [reason, setReason] = useState(''); | ||
|
||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
setIsSubmitting(true); | ||
try { | ||
await onReject(reason); | ||
closeModal(); | ||
} finally { | ||
setIsSubmitting(false); | ||
} | ||
}; | ||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
showCloseIcon={false} | ||
closeModal={closeModal} | ||
title={'Reject Selected'} | ||
className="bg-light--theme-light dark:bg-dark--theme-light p-5 rounded-xl w-full md:w-40 md:min-w-[24rem] justify-start" | ||
titleClass="font-bold"> | ||
<form onSubmit={handleSubmit}> | ||
<div className="flex flex-col gap-4"> | ||
<span className="text-[#71717A] text-center"> | ||
You are about to reject the selected entry, would you like to proceed? | ||
</span> | ||
<textarea | ||
value={reason} | ||
onChange={(e) => setReason(e.target.value)} | ||
placeholder="Add reason here..." | ||
className={clsxm( | ||
"bg-transparent focus:border-transparent focus:ring-2 focus:ring-transparent", | ||
"placeholder-gray-300 placeholder:font-normal resize-none p-2 grow", | ||
"border border-gray-200 dark:border-slate-600 dark:bg-dark--theme-light rounded-md h-40", | ||
reason.length < minReasonLength! && "border-red-500" | ||
)} | ||
maxLength={120} | ||
minLength={0} | ||
aria-label="Rejection reason" | ||
required | ||
/> | ||
<div className="text-sm text-gray-500 text-right"> | ||
{reason.length}/{maxReasonLength} | ||
</div> | ||
<div className="flex items-center gap-x-4 justify-end"> | ||
<button | ||
onClick={closeModal} | ||
type="button" | ||
disabled={isSubmitting} | ||
aria-label="Cancel rejection" | ||
className="dark:text-primary border-[#E2E8F0] dark:border-slate-600 font-normal dark:bg-dark--theme-light h-[2.2rem] text-gray-700 border px-2 rounded-lg" | ||
> | ||
Cancel | ||
</button> | ||
<button | ||
type="submit" | ||
disabled={isSubmitting || reason.length < minReasonLength!} | ||
aria-label="Confirm rejection" | ||
className={clsxm( | ||
'bg-red-600 h-[2.2rem] font-normal flex items-center text-white px-2 rounded-lg', | ||
'disabled:opacity-50 disabled:cursor-not-allowed' | ||
)} > | ||
{isSubmitting ? 'Rejecting...' : 'Reject Entry'} | ||
</button> | ||
</div> | ||
|
||
</div> | ||
</form> | ||
</Modal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters