@@ -161,6 +161,14 @@ const Createplan = () => {
161161 return seriesOptions . some ( ( s ) => s . id === planNewFromSeries . seriesId ) ;
162162 } , [ planNewFromSeries , isSeriesLoading , isSeriesError , seriesOptions ] ) ;
163163
164+ const lockStartDateFromSeries = useMemo (
165+ ( ) =>
166+ isCreateMode &&
167+ planNewFromSeries != null &&
168+ planNewFromSeries . start_date !== undefined ,
169+ [ isCreateMode , planNewFromSeries ] ,
170+ ) ;
171+
164172 const pageHeading = useMemo ( ( ) => {
165173 if ( ! isCreateMode ) return "Plan Edit" ;
166174 if ( ! planNewFromSeries ) return "Plan Details" ;
@@ -213,8 +221,20 @@ const Createplan = () => {
213221 isSeriesLoading ,
214222 isSeriesError ,
215223 seriesOptions ,
224+ form ,
216225 ] ) ;
217226
227+ useEffect ( ( ) => {
228+ if ( ! isCreateMode || ! planNewFromSeries ) return ;
229+ if ( planNewFromSeries . start_date === undefined ) return ;
230+
231+ const mode = planNewFromSeries . start_date ? "specific" : "enroll" ;
232+ setStartDateMode ( mode ) ;
233+ form . setValue ( "start_date" , planNewFromSeries . start_date , {
234+ shouldDirty : false ,
235+ } ) ;
236+ } , [ isCreateMode , planNewFromSeries , form ] ) ;
237+
218238 useEffect ( ( ) => {
219239 if ( planId && planData ) {
220240 form . reset ( {
@@ -590,6 +610,7 @@ const Createplan = () => {
590610 < Pecha . RadioGroup
591611 value = { startDateMode }
592612 onValueChange = { ( v ) => {
613+ if ( lockStartDateFromSeries ) return ;
593614 const mode = v as "enroll" | "specific" ;
594615 setStartDateMode ( mode ) ;
595616 if ( mode === "enroll" ) {
@@ -604,6 +625,7 @@ const Createplan = () => {
604625 < Pecha . RadioGroupItem
605626 value = "enroll"
606627 id = "start-date-enroll"
628+ disabled = { lockStartDateFromSeries }
607629 />
608630 < label
609631 htmlFor = "start-date-enroll"
@@ -616,6 +638,7 @@ const Createplan = () => {
616638 < Pecha . RadioGroupItem
617639 value = "specific"
618640 id = "start-date-specific"
641+ disabled = { lockStartDateFromSeries }
619642 />
620643 < label
621644 htmlFor = "start-date-specific"
@@ -633,7 +656,10 @@ const Createplan = () => {
633656 < Pecha . Button
634657 type = "button"
635658 variant = "outline"
636- disabled = { startDateMode !== "specific" }
659+ disabled = {
660+ lockStartDateFromSeries ||
661+ startDateMode !== "specific"
662+ }
637663 className = "h-12 w-full justify-start gap-2 px-3 font-normal rounded-md"
638664 >
639665 < IoCalendarClearOutline className = "h-4 w-4 text-muted-foreground" />
0 commit comments