generated from HackYourFuture/final-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/reject #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix/reject #157
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
132 changes: 132 additions & 0 deletions
132
client/src/components/appointmentCard/RejectAppointmentModal.tsx
This file contains hidden or 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,132 @@ | ||
| import React, { useState } from "react"; | ||
| import { Appointment } from "../../types/appointments.types"; | ||
| import { useUpdateAppointmentMutation } from "../../features/appointments/mutations/useUpdateAppointmentMutation"; | ||
|
|
||
| interface RejectAppointmentModalProps { | ||
| appointment: Appointment; | ||
| isOpen: boolean; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| export const RejectAppointmentModal = ({ | ||
| appointment, | ||
| isOpen, | ||
| onClose, | ||
| }: RejectAppointmentModalProps) => { | ||
| const [rejectionReason, setRejectionReason] = useState(""); | ||
| const [error, setError] = useState(""); | ||
| const updateAppointmentMutation = useUpdateAppointmentMutation(); | ||
|
|
||
| const handleSubmit = async (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
|
|
||
| if (rejectionReason.trim().length < 100) { | ||
| setError("Rejection reason must be at least 100 characters"); | ||
| return; | ||
| } | ||
|
|
||
| if (rejectionReason.trim().length > 500) { | ||
| setError("Rejection reason must not exceed 500 characters"); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await updateAppointmentMutation.mutateAsync({ | ||
| appointmentId: appointment.id, | ||
| status: "rejected", | ||
| rejectionReason: rejectionReason.trim(), | ||
| }); | ||
| onClose(); | ||
| setRejectionReason(""); | ||
| setError(""); | ||
| } catch { | ||
| setError("Failed to reject appointment. Please try again."); | ||
| } | ||
| }; | ||
|
|
||
| const handleClose = () => { | ||
| onClose(); | ||
| setRejectionReason(""); | ||
| setError(""); | ||
| }; | ||
|
|
||
| if (!isOpen) return null; | ||
|
|
||
| return ( | ||
| <div className="fixed inset-0 backdrop-blur-sm bg-white/5 flex items-center justify-center z-50"> | ||
| <div className="bg-white rounded-lg p-6 w-full max-w-md mx-4"> | ||
| <h2 className="text-xl font-semibold mb-4">Reject Appointment</h2> | ||
|
|
||
| <div className="mb-4"> | ||
| <p className="text-sm text-gray-600 mb-2"> | ||
| <strong>Student:</strong> {appointment.studentName} | ||
| </p> | ||
| <p className="text-sm text-gray-600 mb-2"> | ||
| <strong>Lesson:</strong> {appointment.lesson} | ||
| </p> | ||
| <p className="text-sm text-gray-600 mb-4"> | ||
| <strong>Date & Time:</strong> {appointment.date} at{" "} | ||
| {appointment.time} | ||
| </p> | ||
| </div> | ||
|
|
||
| <form onSubmit={handleSubmit}> | ||
| <div className="mb-4"> | ||
| <label | ||
| htmlFor="rejectionReason" | ||
| className="block text-sm font-medium text-gray-700 mb-2" | ||
| > | ||
| Reason for Rejection * | ||
| </label> | ||
| <textarea | ||
| id="rejectionReason" | ||
| value={rejectionReason} | ||
| onChange={(e) => setRejectionReason(e.target.value)} | ||
| className="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none" | ||
| rows={6} | ||
| placeholder="Please explain why you are rejecting this appointment (100-500 characters)..." | ||
| required | ||
| /> | ||
| <div className="flex justify-between text-xs text-gray-500 mt-1"> | ||
| <span>Minimum 100 characters</span> | ||
| <span | ||
| className={rejectionReason.length > 500 ? "text-red-500" : ""} | ||
| > | ||
| {rejectionReason.length}/500 | ||
| </span> | ||
| </div> | ||
| </div> | ||
|
|
||
| {error && ( | ||
| <div className="mb-4 p-3 bg-red-50 border border-red-200 rounded-lg"> | ||
| <p className="text-sm text-red-700">{error}</p> | ||
| </div> | ||
| )} | ||
|
|
||
| <div className="flex gap-3"> | ||
| <button | ||
| type="button" | ||
| onClick={handleClose} | ||
| className="flex-1 px-4 py-2 text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors" | ||
| disabled={updateAppointmentMutation.isPending} | ||
| > | ||
| Cancel | ||
| </button> | ||
| <button | ||
| type="submit" | ||
| className="flex-1 px-4 py-2 text-white bg-red-600 rounded-lg hover:bg-red-700 transition-colors disabled:opacity-50" | ||
| disabled={ | ||
| updateAppointmentMutation.isPending || | ||
| rejectionReason.trim().length < 100 | ||
| } | ||
| > | ||
| {updateAppointmentMutation.isPending | ||
| ? "Rejecting..." | ||
| : "Reject Appointment"} | ||
| </button> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; |
24 changes: 24 additions & 0 deletions
24
client/src/components/appointmentCard/RejectionReasonDisplay.tsx
This file contains hidden or 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,24 @@ | ||
| import { Appointment } from "../../types/appointments.types"; | ||
|
|
||
| interface RejectionReasonDisplayProps { | ||
| appointment: Appointment; | ||
| } | ||
|
|
||
| export const RejectionReasonDisplay = ({ | ||
| appointment, | ||
| }: RejectionReasonDisplayProps) => { | ||
| if (appointment.status !== "rejected" || !appointment.rejectionReason) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="mt-3 p-3 bg-red-50 border border-red-200 rounded-lg"> | ||
| <h4 className="text-sm font-medium text-red-800 mb-2"> | ||
| Reason for Rejection: | ||
| </h4> | ||
| <p className="text-sm text-red-700 leading-relaxed"> | ||
| {appointment.rejectionReason} | ||
| </p> | ||
| </div> | ||
| ); | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
16 changes: 16 additions & 0 deletions
16
server/src/validation/appointment/rejectionReasonValidation.ts
This file contains hidden or 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,16 @@ | ||
| import { check } from "express-validator"; | ||
|
|
||
| export const rejectionReasonValidation = check("rejectionReason") | ||
| .if(check("status").equals("rejected")) | ||
| .notEmpty() | ||
| .withMessage("Rejection reason is required when rejecting an appointment") | ||
| .isLength({ min: 100, max: 500 }) | ||
| .withMessage("Rejection reason must be between 100 and 500 characters") | ||
| .trim(); | ||
|
|
||
| export const appointmentStatusUpdateValidation = [ | ||
| check("status") | ||
| .isIn(["pending", "approved", "rejected"]) | ||
| .withMessage("Status must be pending, approved, or rejected"), | ||
| rejectionReasonValidation, | ||
| ]; | ||
dashaaaa21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.