@@ -6,7 +6,7 @@ import React from 'react';
66import { FaTelegramPlane } from 'react-icons/fa' ;
77import { FaRegClock } from 'react-icons/fa6' ;
88import { toast } from 'react-toastify' ;
9- import { useApp , useReportInstances } from 'store/hooks' ;
9+ import { useApp , useReportInstances , useReports } from 'store/hooks' ;
1010import {
1111 Claim ,
1212 Col ,
@@ -35,6 +35,7 @@ import * as styled from './styled';
3535export const ReportViewForm : React . FC = ( ) => {
3636 const { values, isSubmitting, setFieldValue, setSubmitting } = useReportEditContext ( ) ;
3737 const [ { sendReportInstance } ] = useReportInstances ( ) ;
38+ const [ , { getReportOwner } ] = useReports ( ) ;
3839 const [ { userInfo } ] = useApp ( ) ;
3940
4041 const [ to , setTo ] = React . useState ( '' ) ;
@@ -47,15 +48,29 @@ export const ReportViewForm: React.FC = () => {
4748 const [ { publishReportInstance } ] = useReportInstances ( ) ;
4849
4950 const handleSend = React . useCallback (
50- async ( id : number , to : string ) => {
51+ async ( instanceId : number , to : string ) => {
5152 try {
52- await sendReportInstance ( id , to ) ;
53+ await sendReportInstance ( instanceId , to ) ;
5354 toast . success ( 'Report has been submitted.' ) ;
5455 } catch { }
5556 } ,
5657 [ sendReportInstance ] ,
5758 ) ;
5859
60+ const handleSendToOwner = React . useCallback (
61+ async ( reportId : number , instanceId : number ) => {
62+ try {
63+ const owner = await getReportOwner ( reportId ) ;
64+ const email = owner ?. preferredEmail ? owner . preferredEmail : owner ?. email ;
65+ if ( ! email ) {
66+ toast . error ( 'This report does not have an owner' ) ;
67+ }
68+ await handleSend ( instanceId , email ! ) ;
69+ } catch { }
70+ } ,
71+ [ getReportOwner , handleSend ] ,
72+ ) ;
73+
5974 const handlePublish = React . useCallback (
6075 async ( instance : IReportInstanceModel , resend : boolean ) => {
6176 try {
@@ -112,16 +127,30 @@ export const ReportViewForm: React.FC = () => {
112127 </ Row >
113128 </ Col >
114129
115- < Show visible = { isAdmin } >
116- < Row gap = "1rem ">
117- < Col flex = "1" >
130+ < Row gap = "1rem" >
131+ < Col flex = "1 ">
132+ < Show visible = { isAdmin || ! ! values . ownerId } >
118133 < Row alignItems = "baseline" gap = "0.5rem" >
119134 < FaRegClock />
120135 < div className = "preview-block-headline" > Send a Test</ div >
121136 </ Row >
122-
137+ < Row alignItems = "flex-start" className = "preview-send-details-row" >
138+ < Button
139+ className = "send-test-button"
140+ disabled = { isSubmitting }
141+ variant = "secondary"
142+ onClick = { ( ) => ! ! instance ?. id && handleSendToOwner ( values . id , instance . id ) }
143+ style = { { backgroundColor : 'transparent' } }
144+ >
145+ < FaTelegramPlane />
146+ Send to Report Owner
147+ </ Button >
148+ </ Row >
149+ </ Show >
150+ < Show visible = { isAdmin } >
123151 < Row alignItems = "flex-start" className = "preview-send-details-row" >
124152 < Col >
153+ < hr />
125154 < p >
126155 Sending a report to a specific email address does not register the 'Last sent'
127156 date. Only use this for testing.
@@ -147,9 +176,9 @@ export const ReportViewForm: React.FC = () => {
147176 </ Text >
148177 </ Col >
149178 </ Row >
150- </ Col >
151- </ Row >
152- </ Show >
179+ </ Show >
180+ </ Col >
181+ </ Row >
153182
154183 < Row gap = "1rem" >
155184 < Col flex = "1" >
0 commit comments