11import { useMemo , useState } from 'react' ;
2+ import { useGlobal } from '../context/useGlobal' ;
23import {
34 IAlertStrings ,
5+ IMediaTabStrings ,
6+ IPlanSheetStrings ,
47 IPublishLevelStrings ,
58 IPublishToStrings ,
9+ IPassageTypeStrings ,
610 ISharedStrings ,
711} from '../model' ;
812import {
@@ -24,25 +28,30 @@ import DialogActions from '@mui/material/DialogActions';
2428import { shallowEqual , useSelector } from 'react-redux' ;
2529import {
2630 alertSelector ,
31+ mediaTabSelector ,
32+ passageTypeSelector ,
33+ planSheetSelector ,
2734 publishLevelSelector ,
2835 publishToSelector ,
2936 sharedSelector ,
3037} from '../selector' ;
31- import { PublishLevelEnum , usePublishDestination } from '../crud' ;
38+ import {
39+ PublishLevelEnum ,
40+ useBible ,
41+ useOrganizedBy ,
42+ usePublishDestination ,
43+ } from '../crud' ;
3244import ShowLink from '../control/ShowLink' ;
3345import { PublishDestinationEnum } from '../crud' ;
3446import { PassageTypeEnum } from '../model/passageType' ;
3547import { Akuo , Aquifer , ObtHelps } from '../assets/brands' ;
3648
3749interface IProps {
38- title : string ;
39- propagateLabel : string ;
40- description : string ;
41- noPropagateDescription : string ;
50+ context : 'plan' | 'media' ;
51+ isMovement ?: boolean ;
4252 current : PublishDestinationEnum [ ] ;
4353 sharedProject : boolean ;
4454 hasPublishing : boolean ;
45- hasBible : boolean ;
4655 noDefaults ?: boolean ;
4756 passageType ?: PassageTypeEnum ;
4857 noResponse : ( ) => void ;
@@ -51,28 +60,48 @@ interface IProps {
5160
5261function ConfirmPublishDialog ( props : IProps ) {
5362 const {
54- title,
55- propagateLabel,
56- description,
57- noPropagateDescription,
63+ context,
64+ isMovement,
5865 sharedProject,
5966 hasPublishing,
60- hasBible,
6167 yesResponse,
6268 noResponse,
6369 current,
6470 noDefaults,
6571 passageType,
6672 } = props ;
6773
68- const t : IAlertStrings = useSelector ( alertSelector , shallowEqual ) ;
69- const ts : ISharedStrings = useSelector ( sharedSelector , shallowEqual ) ;
74+ const alertStrings : IAlertStrings = useSelector ( alertSelector , shallowEqual ) ;
75+ const mediaStrings : IMediaTabStrings = useSelector (
76+ mediaTabSelector ,
77+ shallowEqual
78+ ) ;
79+ const planSheetStrings : IPlanSheetStrings = useSelector (
80+ planSheetSelector ,
81+ shallowEqual
82+ ) ;
83+ const passageTypeStrings : IPassageTypeStrings = useSelector (
84+ passageTypeSelector ,
85+ shallowEqual
86+ ) ;
87+ const sharedStrings : ISharedStrings = useSelector (
88+ sharedSelector ,
89+ shallowEqual
90+ ) ;
7091 const l : IPublishLevelStrings = useSelector (
7192 publishLevelSelector ,
7293 shallowEqual
7394 ) ;
7495 const { getDefaults } = usePublishDestination ( ) ;
7596 const p : IPublishToStrings = useSelector ( publishToSelector , shallowEqual ) ;
97+ const { getOrganizedBy } = useOrganizedBy ( ) ;
98+ const [ org ] = useGlobal ( 'organization' ) ;
99+ const { getOrgBible } = useBible ( ) ;
100+ const hasBible = useMemo ( ( ) => {
101+ if ( ! org ) return false ;
102+ const bible = getOrgBible ( org ) ;
103+ return ( bible ?. attributes . bibleName ?? '' ) !== '' ;
104+ } , [ getOrgBible , org ] ) ;
76105 const [ open , setOpen ] = useState ( true ) ;
77106 const [ propagate , setPropagate ] = useState ( true ) ;
78107 const [ value , setValuex ] = useState (
@@ -93,6 +122,85 @@ function ConfirmPublishDialog(props: IProps) {
93122 const [ akuoValue , setAkuoValue ] = useState < PublishLevelEnum > (
94123 calcAkuoValue ( value )
95124 ) ;
125+ const usePlanLabels = context === 'plan' ;
126+ const organizedLabel = getOrganizedBy ( true ) ;
127+ const organizedPluralLabel = getOrganizedBy ( false ) ;
128+ const isMovementRow = Boolean ( isMovement ) ;
129+ const dialogTitle = useMemo ( ( ) => {
130+ if ( ! usePlanLabels ) return mediaStrings . publish ;
131+ return planSheetStrings . confirmPublish . replace (
132+ '{0}' ,
133+ isMovementRow ? passageTypeStrings . MOVE : organizedLabel
134+ ) ;
135+ } , [
136+ usePlanLabels ,
137+ mediaStrings . publish ,
138+ planSheetStrings . confirmPublish ,
139+ passageTypeStrings . MOVE ,
140+ isMovementRow ,
141+ organizedLabel ,
142+ ] ) ;
143+ const propagateLabel = useMemo ( ( ) => {
144+ if ( ! usePlanLabels ) return '' ;
145+ return planSheetStrings . propagate
146+ . replaceAll (
147+ '{0}' ,
148+ isMovementRow
149+ ? organizedPluralLabel . toLocaleLowerCase ( )
150+ : sharedStrings . passages . toLocaleLowerCase ( )
151+ )
152+ . replaceAll (
153+ '{1}' ,
154+ isMovementRow
155+ ? planSheetStrings . movement . toLocaleLowerCase ( )
156+ : organizedLabel . toLocaleLowerCase ( )
157+ ) ;
158+ } , [
159+ usePlanLabels ,
160+ planSheetStrings . propagate ,
161+ planSheetStrings . movement ,
162+ sharedStrings . passages ,
163+ isMovementRow ,
164+ organizedLabel ,
165+ organizedPluralLabel ,
166+ ] ) ;
167+ const description = useMemo ( ( ) => {
168+ if ( ! usePlanLabels ) return '' ;
169+ return isMovementRow
170+ ? planSheetStrings . confirmPublishMovement . replaceAll (
171+ '{0}' ,
172+ organizedPluralLabel . toLocaleLowerCase ( )
173+ )
174+ : planSheetStrings . confirmPublishSection . replaceAll (
175+ '{0}' ,
176+ organizedLabel . toLocaleLowerCase ( )
177+ ) ;
178+ } , [
179+ usePlanLabels ,
180+ planSheetStrings . confirmPublishMovement ,
181+ planSheetStrings . confirmPublishSection ,
182+ isMovementRow ,
183+ organizedLabel ,
184+ organizedPluralLabel ,
185+ ] ) ;
186+ const noPropagateDescription = useMemo ( ( ) => {
187+ if ( ! usePlanLabels ) return '' ;
188+ return isMovementRow
189+ ? planSheetStrings . confirmPublishMovementNoPropagate
190+ . replaceAll ( '{0}' , organizedPluralLabel . toLocaleLowerCase ( ) )
191+ . replaceAll ( '{1}' , Akuo )
192+ : planSheetStrings . confirmPublishSectionNoPropagate . replaceAll (
193+ '{0}' ,
194+ organizedLabel . toLocaleLowerCase ( )
195+ ) ;
196+ } , [
197+ usePlanLabels ,
198+ planSheetStrings . confirmPublishMovementNoPropagate ,
199+ planSheetStrings . confirmPublishSectionNoPropagate ,
200+ isMovementRow ,
201+ organizedLabel ,
202+ organizedPluralLabel ,
203+ ] ) ;
96204 const setValue = ( val : PublishDestinationEnum [ ] ) => {
97205 setValuex ( val ) ;
98206 setAkuoValue ( calcAkuoValue ( val ) ) ;
@@ -228,7 +336,7 @@ function ConfirmPublishDialog(props: IProps) {
228336 aria-describedby = "confirmPublishDesc"
229337 disableEnforceFocus
230338 >
231- < DialogTitle id = "alertDlg" > { title } </ DialogTitle >
339+ < DialogTitle id = "alertDlg" > { dialogTitle } </ DialogTitle >
232340 < DialogContent >
233341 < DialogContent id = "alertJsx" >
234342 { hasPublishing && ! hasBible && (
@@ -324,7 +432,9 @@ function ConfirmPublishDialog(props: IProps) {
324432 ) }
325433 </ FormControl >
326434 </ DialogContent >
327- < DialogContentText id = "alertDesc" > { t . areYouSure } </ DialogContentText >
435+ < DialogContentText id = "alertDesc" >
436+ { alertStrings . areYouSure }
437+ </ DialogContentText >
328438 </ DialogContent >
329439 < DialogActions >
330440 < Button
@@ -333,7 +443,7 @@ function ConfirmPublishDialog(props: IProps) {
333443 color = "primary"
334444 disabled = { doingIt }
335445 >
336- { value === current ? ts . cancel : t . no }
446+ { value === current ? sharedStrings . cancel : alertStrings . no }
337447 </ Button >
338448 < Button
339449 id = "alertYes"
@@ -343,7 +453,7 @@ function ConfirmPublishDialog(props: IProps) {
343453 disabled = { value === current || ( ! hasBible && needsBibleId ) || doingIt }
344454 autoFocus
345455 >
346- { t . yes }
456+ { alertStrings . yes }
347457 </ Button >
348458 </ DialogActions >
349459 </ Dialog >
0 commit comments