From 54973dee173da59a0560ed26b626c1562222218e Mon Sep 17 00:00:00 2001 From: amirhbeigi Date: Sat, 27 Apr 2024 20:06:45 +0430 Subject: [PATCH] feat: add duration to workhours fragment and add error toast for remove expertise --- .plasmic/plasmic/opium/PlasmicDaysOfWeek.jsx | 20 +- .plasmic/plasmic/opium/PlasmicWorkhours.jsx | 278 ++- apps/drapp/public/pwa-versions/latest.json | 2 +- .../components/profile/expertises/index.jsx | 3 + .../pages/drApp/setting/workHours/index.tsx | 85 +- package-lock.json | 42 +- plasmic.json | 15 +- plasmic.lock | 12 +- yarn.lock | 1751 +++++++++++------ 9 files changed, 1459 insertions(+), 749 deletions(-) diff --git a/.plasmic/plasmic/opium/PlasmicDaysOfWeek.jsx b/.plasmic/plasmic/opium/PlasmicDaysOfWeek.jsx index a04d0cf0..83ea3acf 100644 --- a/.plasmic/plasmic/opium/PlasmicDaysOfWeek.jsx +++ b/.plasmic/plasmic/opium/PlasmicDaysOfWeek.jsx @@ -31,7 +31,8 @@ export const PlasmicDaysOfWeek__VariantProps = new Array(); export const PlasmicDaysOfWeek__ArgProps = new Array( "selectedDay", - "selectTrigger" + "selectTrigger", + "cancelTrigger" ); const $$ = {}; @@ -372,6 +373,23 @@ function PlasmicDaysOfWeek__RenderFunc(props) { "updateSelectAllIsChecked" ]; } + $steps["updateSelectAllIsChecked2"] = true + ? (() => { + const actionArgs = { eventRef: $props["cancelTrigger"] }; + return (({ eventRef, args }) => { + return eventRef?.(...(args ?? [])); + })?.apply(null, [actionArgs]); + })() + : undefined; + if ( + $steps["updateSelectAllIsChecked2"] != null && + typeof $steps["updateSelectAllIsChecked2"] === "object" && + typeof $steps["updateSelectAllIsChecked2"].then === "function" + ) { + $steps["updateSelectAllIsChecked2"] = await $steps[ + "updateSelectAllIsChecked2" + ]; + } }} /> diff --git a/.plasmic/plasmic/opium/PlasmicWorkhours.jsx b/.plasmic/plasmic/opium/PlasmicWorkhours.jsx index 92174b88..5433f538 100644 --- a/.plasmic/plasmic/opium/PlasmicWorkhours.jsx +++ b/.plasmic/plasmic/opium/PlasmicWorkhours.jsx @@ -17,6 +17,7 @@ import { get as $stateGet, initializeCodeComponentStates, initializePlasmicStates, + set as $stateSet, useCurrentUser, useDollarState } from "@plasmicapp/react-web"; @@ -260,11 +261,9 @@ function PlasmicWorkhours__RenderFunc(props) { ? (() => { const actionArgs = { customFunction: async () => { - return (() => { - return ($state.listOfWorkhoureCopy[ - currentIndex - ].to = $state.to[currentIndex].value); - })(); + return ($state.listOfWorkhoureCopy[ + currentIndex + ].to = $state.to[currentIndex].value); } }; return (({ customFunction }) => { @@ -279,6 +278,68 @@ function PlasmicWorkhours__RenderFunc(props) { ) { $steps["runCode"] = await $steps["runCode"]; } + $steps["updateWarning"] = true + ? (() => { + const actionArgs = { + variable: { + objRoot: $state, + variablePath: ["warning"] + }, + operation: 0, + value: $state.listOfWorkhoureCopy.some( + (item, index) => + index !== currentIndex + ? (new Date( + `2000-01-01T${currentItem.from}:00` + ).getTime() >= + new Date( + `2000-01-01T${item.from}:00` + ).getTime() && + new Date( + `2000-01-01T${currentItem.from}:00` + ).getTime() < + new Date( + `2000-01-01T${item.to}:00` + ).getTime()) || + (new Date( + `2000-01-01T${currentItem.to}:00` + ).getTime() > + new Date( + `2000-01-01T${item.from}:00` + ).getTime() && + new Date( + `2000-01-01T${currentItem.to}:00` + ).getTime() <= + new Date( + `2000-01-01T${item.to}:00` + ).getTime()) + : item.from === item.to + ) + }; + return (({ + variable, + value, + startIndex, + deleteCount + }) => { + if (!variable) { + return; + } + const { objRoot, variablePath } = variable; + $stateSet(objRoot, variablePath, value); + return value; + })?.apply(null, [actionArgs]); + })() + : undefined; + if ( + $steps["updateWarning"] != null && + typeof $steps["updateWarning"] === "object" && + typeof $steps["updateWarning"].then === "function" + ) { + $steps["updateWarning"] = await $steps[ + "updateWarning" + ]; + } }).apply(null, eventArgs); }, options: (() => { @@ -286,11 +347,15 @@ function PlasmicWorkhours__RenderFunc(props) { return (() => { const duration = $props.duration; const options = []; - const initialHour = 21; + const initialHour = currentItem.from.split(":")[0]; for (let i = 1; i <= 24; i++) { const totalMinutes = initialHour * 60 + i * duration; const hour = Math.floor(totalMinutes / 60) % 24; + if (hour === 0) { + options.push("23:59"); + break; + } const minute = totalMinutes % 60; const formattedHour = `${ hour < 10 ? "0" : "" @@ -376,11 +441,9 @@ function PlasmicWorkhours__RenderFunc(props) { ? (() => { const actionArgs = { customFunction: async () => { - return (() => { - return ($state.listOfWorkhoureCopy[ - currentIndex - ].from = $state.from[currentIndex].value); - })(); + return ($state.listOfWorkhoureCopy[ + currentIndex + ].from = $state.from[currentIndex].value); } }; return (({ customFunction }) => { @@ -395,6 +458,68 @@ function PlasmicWorkhours__RenderFunc(props) { ) { $steps["runCode"] = await $steps["runCode"]; } + $steps["updateWarning"] = true + ? (() => { + const actionArgs = { + variable: { + objRoot: $state, + variablePath: ["warning"] + }, + operation: 0, + value: $state.listOfWorkhoureCopy.some( + (item, index) => + index !== currentIndex + ? (new Date( + `2000-01-01T${currentItem.from}:00` + ).getTime() >= + new Date( + `2000-01-01T${item.from}:00` + ).getTime() && + new Date( + `2000-01-01T${currentItem.from}:00` + ).getTime() < + new Date( + `2000-01-01T${item.to}:00` + ).getTime()) || + (new Date( + `2000-01-01T${currentItem.to}:00` + ).getTime() > + new Date( + `2000-01-01T${item.from}:00` + ).getTime() && + new Date( + `2000-01-01T${currentItem.to}:00` + ).getTime() <= + new Date( + `2000-01-01T${item.to}:00` + ).getTime()) + : item.from === item.to + ) + }; + return (({ + variable, + value, + startIndex, + deleteCount + }) => { + if (!variable) { + return; + } + const { objRoot, variablePath } = variable; + $stateSet(objRoot, variablePath, value); + return value; + })?.apply(null, [actionArgs]); + })() + : undefined; + if ( + $steps["updateWarning"] != null && + typeof $steps["updateWarning"] === "object" && + typeof $steps["updateWarning"].then === "function" + ) { + $steps["updateWarning"] = await $steps[ + "updateWarning" + ]; + } }).apply(null, eventArgs); }, options: (() => { @@ -663,35 +788,34 @@ function PlasmicWorkhours__RenderFunc(props) { }, trigger: (() => { try { - return ($state.warning = - $state.listOfWorkhoureCopy.some((item, index) => - index !== currentIndex - ? (new Date( + return $state.listOfWorkhoureCopy.some((item, index) => + index !== currentIndex + ? (new Date( + `2000-01-01T${currentItem.from}:00` + ).getTime() >= + new Date( + `2000-01-01T${item.from}:00` + ).getTime() && + new Date( `2000-01-01T${currentItem.from}:00` - ).getTime() >= - new Date( - `2000-01-01T${item.from}:00` - ).getTime() && + ).getTime() < new Date( - `2000-01-01T${currentItem.from}:00` - ).getTime() < - new Date( - `2000-01-01T${item.to}:00` - ).getTime()) || - (new Date( + `2000-01-01T${item.to}:00` + ).getTime()) || + (new Date( + `2000-01-01T${currentItem.to}:00` + ).getTime() > + new Date( + `2000-01-01T${item.from}:00` + ).getTime() && + new Date( `2000-01-01T${currentItem.to}:00` - ).getTime() > + ).getTime() <= new Date( - `2000-01-01T${item.from}:00` - ).getTime() && - new Date( - `2000-01-01T${currentItem.to}:00` - ).getTime() <= - new Date( - `2000-01-01T${item.to}:00` - ).getTime()) - : item.from === item.to - )); + `2000-01-01T${item.to}:00` + ).getTime()) + : item.from === item.to + ); } catch (e) { if ( e instanceof TypeError || @@ -763,6 +887,48 @@ function PlasmicWorkhours__RenderFunc(props) { { + const $steps = {}; + $steps["updateFragmentPopover0Open"] = true + ? (() => { + const actionArgs = { + variable: { + objRoot: $state, + variablePath: [ + "fragmentPopover", + "0", + "open" + ] + }, + operation: 0, + value: false + }; + return (({ + variable, + value, + startIndex, + deleteCount + }) => { + if (!variable) { + return; + } + const { objRoot, variablePath } = variable; + $stateSet(objRoot, variablePath, value); + return value; + })?.apply(null, [actionArgs]); + })() + : undefined; + if ( + $steps["updateFragmentPopover0Open"] != null && + typeof $steps["updateFragmentPopover0Open"] === + "object" && + typeof $steps["updateFragmentPopover0Open"] + .then === "function" + ) { + $steps["updateFragmentPopover0Open"] = + await $steps["updateFragmentPopover0Open"]; + } + }} className={classNames( "__wab_instance", sty.daysOfWeek @@ -806,28 +972,44 @@ function PlasmicWorkhours__RenderFunc(props) { "runEndedSelectedDay" ]; } - $steps["runActionOnFragmentPopover"] = true + $steps["updateFragmentPopover0Open"] = true ? (() => { const actionArgs = { - tplRef: "fragmentPopover", - action: "close" + variable: { + objRoot: $state, + variablePath: [ + "fragmentPopover", + "0", + "open" + ] + }, + operation: 0, + value: false }; - return (({ tplRef, action, args }) => { - return $refs?.[tplRef]?.[action]?.( - ...(args ?? []) - ); + return (({ + variable, + value, + startIndex, + deleteCount + }) => { + if (!variable) { + return; + } + const { objRoot, variablePath } = variable; + $stateSet(objRoot, variablePath, value); + return value; })?.apply(null, [actionArgs]); })() : undefined; if ( - $steps["runActionOnFragmentPopover"] != null && - typeof $steps["runActionOnFragmentPopover"] === + $steps["updateFragmentPopover0Open"] != null && + typeof $steps["updateFragmentPopover0Open"] === "object" && - typeof $steps["runActionOnFragmentPopover"] + typeof $steps["updateFragmentPopover0Open"] .then === "function" ) { - $steps["runActionOnFragmentPopover"] = - await $steps["runActionOnFragmentPopover"]; + $steps["updateFragmentPopover0Open"] = + await $steps["updateFragmentPopover0Open"]; } }} selectedDay={(() => { diff --git a/apps/drapp/public/pwa-versions/latest.json b/apps/drapp/public/pwa-versions/latest.json index 5f8d6b11..fb637788 100644 --- a/apps/drapp/public/pwa-versions/latest.json +++ b/apps/drapp/public/pwa-versions/latest.json @@ -1,5 +1,5 @@ { - "name": "3.175.0", + "name": "3.180.0", "changeLog": "", "tags": [] } diff --git a/apps/drapp/src/components/profile/expertises/index.jsx b/apps/drapp/src/components/profile/expertises/index.jsx index e58fd5e2..cc4583cc 100644 --- a/apps/drapp/src/components/profile/expertises/index.jsx +++ b/apps/drapp/src/components/profile/expertises/index.jsx @@ -97,6 +97,9 @@ export const Expertises = props => { }); } props.setExpertise(visitesList); + }, + onError: error => { + toast.error(error.response.data.message); } } ); diff --git a/apps/drapp/src/pages/drApp/setting/workHours/index.tsx b/apps/drapp/src/pages/drApp/setting/workHours/index.tsx index ca92511d..e1bf56f1 100644 --- a/apps/drapp/src/pages/drApp/setting/workHours/index.tsx +++ b/apps/drapp/src/pages/drApp/setting/workHours/index.tsx @@ -41,6 +41,7 @@ const WorkHours = () => { const getWorkHoursRequest = useGetWorkHours({ center_id: doctorInfo.center.id }); const removeWorkHours = useWorkHoursStore(state => state.removeWorkHours); const duration = useWorkHoursStore(state => state.duration); + const [previousDuration, setPreviousDuration] = useState(duration); const setDuration = useWorkHoursStore(state => state.setDuration); const [activationModal, setActivationModal] = useState(false); const completedActivationNotice = useFeatureValue( @@ -51,16 +52,15 @@ const WorkHours = () => { const useFragment = useFeatureIsOn('show-fragment-workhour-page'); useEffect(() => { - if (!useFragment) { - getWorkHoursRequest.remove(); - getWorkHoursRequest.refetch(); - } + getWorkHoursRequest.remove(); + getWorkHoursRequest.refetch(); }, [doctorInfo.center]); useEffect(() => { if (getWorkHoursRequest.isSuccess) { setWorkHours(getWorkHoursRequest.data.data.workhours); setDuration(getWorkHoursRequest.data.data.duration); + setPreviousDuration(getWorkHoursRequest.data.data.duration); } }, [getWorkHoursRequest.status]); @@ -101,9 +101,12 @@ const WorkHours = () => { handleSubmit({ workHours: workHourClone, duration }); }; - const handleSetDuration = (duration: number) => { - setDuration(duration); - handleSubmit({ workHours, duration }); + const handleSetDuration = (prevDuration: number, newDuration: number) => { + setPreviousDuration(prevDuration); + setDuration(newDuration); + handleSubmit({ workHours, duration: newDuration }).catch(() => { + setDuration(prevDuration); + }); }; const handleSubmit = async ({ @@ -132,34 +135,20 @@ const WorkHours = () => { error: error.response?.data } }); + return Promise.reject(error); } } }; - if (useFragment) { - return ( - - - - ); - } - return ( { + handleSetDuration(duration, newDuration); + }} label={ getCenterType(doctorInfo.center) === 'consult' ? 'مدت زمان‌ ایده‌آل شما برای ارائه یک ویزیت جامع و پیوسته به یک بیمار چقدر است؟' @@ -175,22 +164,36 @@ const WorkHours = () => { پاسخگویی به سوالات احتمالی بیمار در دسترس باشید. )} - - - - - + {useFragment && ( + + )} + {!useFragment && ( + <> + + + + + + + )} {queryString.parse(window.location.search)['activation-path'] && (