Files
nobat724_front/services/response.js
T
hamedandClaude Opus 5 4c912dc6c1 feat(panel): let a patient actually cancel or move their own appointment
The site's own copy has been promising cancellation for a while —
lib/specialtyContent.js and components/appointment/information/Detail.js both
tell users they can cancel from "نوبت‌های من" and get a refund up to five hours
before the visit. The UI never could. The cancel modal existed, but its confirm
button called handleClose: it closed the dialog and sent nothing. And the whole
button row it lived in (ButtonData.js) had been commented out since the PDF
download commit, so it was not even reachable.

Cancelling now goes through POST /appointment/{uuid}/cancel and shows the
penalty from /cancellation-preview before the confirm — the same calculation
the cancel itself runs, so the number the patient sees is the number they are
charged. If the preview fails, the dialog says so rather than blocking; the
cancellation is still allowed.

Rescheduling is new and service-aware. It asks for slots with
exclude_appointment_uuid, so the patient's own hour counts as free rather than
showing as taken, and it sends only the start time — the server computes the
duration. Sending a client-side duration would mean two parallel calculations,
and the day a service's minutes change the appointment would move with a stale
one. The services on the appointment are carried over unchanged.

Both actions only appear for an appointment that is still in the future and not
already cancelled, and both refresh the list afterwards so a just-cancelled
appointment stops showing as confirmed.

The day strip in the reschedule modal is its own small component rather than
the booking flow's DatePicker: that one reads the doctor uuid from route params
and would be undefined inside the dashboard.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-01 14:32:10 +03:30

214 lines
8.4 KiB
JavaScript

import { removeTokenHead } from "@/helper";
import api from "./api";
/**
* محل نوبت‌دهی. نبودِ clinic_uuid یعنی «مطب شخصی» — نه «هر محلی که پیدا شد».
* پزشک می‌تواند هم‌زمان برنامهٔ شخصی و برنامهٔ کلینیک داشته باشد و این دو داده‌ی
* جدا دارند.
*/
const clinicQuery = (clinicUuid, prefix = "&") =>
clinicUuid ? `${prefix}clinic_uuid=${encodeURIComponent(clinicUuid)}` : "";
export const request = {
sendCode: (mobile, altcha, domain) =>
api.post(
"api/v1/user/send-code",
{
mobile,
altcha,
...(domain ? { domain } : {}),
},
removeTokenHead
),
getUserProfile: (uuid) => api.get(`/api/v1/user-profile/${uuid}`, { requireAuth: true }),
postUserProfile: (data) => api.post("api/v1/user-profile", data, { requireAuth: true }),
patchUserProfile: (data, uuid) =>
api.patch(`api/v1/user-profile/${uuid}`, data, { requireAuth: true }),
uploadUserAvatar: (file) =>
api.post("api/v1/user-profile/avatar", file, {
requireAuth: true,
headers: {
"Content-Type": "application/octet-stream",
"Content-Disposition": `filename="${file?.name || "avatar.jpg"}"`,
},
}),
getUserInfo: (headers) => api.get("oauth/userinfo", { ...headers, requireAuth: true }),
getInsuranceType: () =>
api.get(`api/v1/insurances?type=basic`, { requireAuth: true }),
getSupplementaryInsurance: () =>
api.get(`api/v1/insurances?type=supplementary`, { requireAuth: true }),
getDoctors: (params) =>
api.get("api/v1/doctors", {
params,
headers: {
Authorization: "",
},
}),
getSpecialtyDoctorCounts: (cityId) =>
api.get("api/v1/specialties/doctor-counts", {
params: cityId ? { city_id: cityId } : {},
headers: { Authorization: "" },
}),
getAppointmentWeeklySchedule: (uuid) =>
api.get(`api/v1/appointment-settings/weekly-schedule/${uuid}`),
postAppointmentWeeklySchedule: () =>
api.post("api/v1/appointment-settings/weekly-schedule/"),
patchAppointmentWeeklySchedule: (uuid) =>
api.patch(`api/v1/appointment-settings/weekly-schedule/${uuid}`),
deleteAppointmentWeeklySchedule: (uuid) =>
api.delete(`api/v1/appointment-settings/weekly-schedule/${uuid}`),
getBookingLocations: (doctor_uuid, date = null) =>
api.get(`api/v1/appointment-booking-locations/${doctor_uuid}`, {
params: date ? { date } : {},
...removeTokenHead,
}),
getAppointmentSlots: (doctor_uuid, date, clinic_uuid = null) =>
api.get(
`api/v1/appointment-slots?doctor_uuid=${doctor_uuid}&date=${date}` +
clinicQuery(clinic_uuid),
removeTokenHead
),
getMonthAvailability: (doctor_uuid, year, month, clinic_uuid = null) =>
api.get(`api/v1/appointment-settings/month-availability/${doctor_uuid}`, {
params: { year, month, ...(clinic_uuid ? { clinic_uuid } : {}) },
...removeTokenHead,
}),
getBookingServices: (doctor_uuid, clinic_uuid = null) =>
api.get(
`api/v1/appointment-booking-services/${doctor_uuid}${clinicQuery(clinic_uuid, "?")}`,
removeTokenHead
),
getServiceSlots: (doctor_uuid, date, serviceItemUuids = [], clinic_uuid = null) =>
api.get(
`api/v1/appointment-service-slots?doctor_uuid=${doctor_uuid}&date=${date}` +
serviceItemUuids
.map((u) => `&service_item_uuids[]=${encodeURIComponent(u)}`)
.join("") +
clinicQuery(clinic_uuid),
removeTokenHead
),
postAppointment: (data) => api.post(`api/v1/appointment`, data, { requireAuth: true }),
/**
* وقت‌های آزاد برای **جابه‌جایی** یک نوبت.
*
* `exclude_appointment_uuid` باعث می‌شود خودِ نوبت فعلی جای خالی حساب شود؛ بدون آن،
* بیمار ساعت خودش را «پر» می‌بیند و نمی‌تواند مثلاً فقط سرویس‌هایش را عوض کند.
* سرور مالکیت آن uuid را می‌سنجد، پس این پارامتر ظرفیت ساختگی نمی‌سازد.
*/
getServiceSlotsForReschedule: (
doctor_uuid,
date,
appointment_uuid,
serviceItemUuids = [],
clinic_uuid = null
) =>
api.get(
`api/v1/appointment-service-slots?doctor_uuid=${doctor_uuid}&date=${date}` +
`&exclude_appointment_uuid=${encodeURIComponent(appointment_uuid)}` +
serviceItemUuids
.map((u) => `&service_item_uuids[]=${encodeURIComponent(u)}`)
.join("") +
clinicQuery(clinic_uuid),
{ requireAuth: true }
),
/** مدت را سرور حساب می‌کند؛ بیمار فقط زمان شروع (و در صورت تغییر، سرویس‌ها) می‌فرستد. */
serviceReschedule: (appointment_uuid, data) =>
api.post(`api/v1/appointment/${appointment_uuid}/service-reschedule`, data, {
requireAuth: true,
}),
/** پیامد مالی لغو، پیش از تأیید — همان محاسبه‌ای که خودِ لغو انجام می‌دهد. */
getCancellationPreview: (appointment_uuid) =>
api.get(`api/v1/appointment/${appointment_uuid}/cancellation-preview`, {
requireAuth: true,
}),
cancelAppointment: (appointment_uuid, data = {}) =>
api.post(`api/v1/appointment/${appointment_uuid}/cancel`, data, { requireAuth: true }),
getMyAppointments: (params) => api.get(`api/v1/appointments/user`, { params, requireAuth: true }),
getPaymentConfig: () => api.get(`api/v1/payment/config`, { requireAuth: true }),
getPayment: (uuid) => api.get(`api/v1/payment/${uuid}`, { requireAuth: true }),
getMyPayments: (params) => api.get(`api/v1/my/payments`, { params, requireAuth: true }),
postDoctor: (data) => api.post("api/v1/doctor", data),
postImageUpload: (data) =>
api.post("file/upload/clinic_pro/doctor/field_image", data, {
headers: {
"Content-Type": "application/octet-stream",
"Content-Disposition": `file; filename="${data.name}"`,
"X-CSRF-Token": "",
},
}),
getDoctorServices: () =>
api.get("api/v1/categorys/doctor_services", removeTokenHead),
postDoctorComment: (data) => api.post("api/v1/comment", data, { requireAuth: true }),
getDoctorClaimInfo: (uuid) => api.get(`api/v1/doctor/${uuid}/claim-info`),
postDoctorClaim: (uuid, data) =>
api.post(`api/v1/doctor/${uuid}/claim`, data, { requireAuth: true }),
deleteDoctor: (uuid) => api.delete(`api/v1/doctor/${uuid}`, { requireAuth: true }),
getDoctorRate: (uuid) => api.get(`api/v1/rate/${uuid}`),
getRateEligibility: (uuid) =>
api.get(`api/v1/rate/${uuid}/eligibility`, { requireAuth: true }),
getDoctorComments: (uuid) => api.get(`api/v1/comments/${uuid}`),
postDoctorRate: (data) => api.post("api/v1/rate", data, { requireAuth: true }),
postCommentsLike: (commentUuid, value) =>
api.post(`api/v1/like/${commentUuid}`, { value }, { requireAuth: true }),
getClinicList: (params) =>
api.get("/api/v1/clinics", {
params,
headers: {
Authorization: "",
},
}),
getDoctorAddress: (location_id) =>
api.get(`api/v1/clinic-pro/doctor-address/${location_id}`, removeTokenHead),
getBlogs: (params) =>
api.get("api/v1/blogs", {
params,
headers: {
Authorization: "",
},
}),
// واژگان تگ‌های مقالات منتشرشده + تعداد هرکدام. با getBlogTags یکی نیست: آن
// واژگانِ Tag entity است و به مقاله‌ها وصل نیست.
getBlogTagFacets: (params) =>
api.get("api/v1/blogs/tags", {
params,
headers: {
Authorization: "",
},
}),
getBlogTags: (params) =>
api.get("api/v1/tags", {
params,
headers: {
Authorization: "",
},
}),
getTopBlogs: () =>
api.get("api/v1/blogs/top", {
headers: {
Authorization: "",
},
}),
getSingleBlog: (uuid) =>
api.get(`api/v1/blog/${uuid}`, {
headers: {
Authorization: "",
},
}),
getRepresentationInfo: (uuid) =>
api.get(`api/v1/representation/${uuid}`, { requireAuth: true }),
getRepresentationDashboardMonthly: (uuid, year, month) =>
api.get(`api/v1/representation/${uuid}/dashboard/monthly`, {
params: { year, month },
requireAuth: true,
}),
getRepresentationDashboardYearly: (uuid, year) =>
api.get(`api/v1/representation/${uuid}/dashboard/yearly`, {
params: { year },
requireAuth: true,
}),
};