@@ -2,12 +2,11 @@ import { Button, Field, Textarea, Toast, ToastTitle, makeStyles } from "@fluentu
22import { useConst } from "@fluentui/react-hooks" ;
33import { useState } from "react" ;
44import { Flex } from "~/Helpers/Styles" ;
5- import { useSWR } from "~/Helpers/useSWR" ;
65import { useErrorToast } from "~/Helpers/useToast" ;
76import { Hub } from "~/ShopNet" ;
87import { AdminHub } from "~/ShopNet/Admin" ;
9- import { SignalR } from "~/ShopNet/SignalR " ;
10- import { IOrderRef } from "." ;
8+ import { IOrderComp } from ". " ;
9+ import { useOrder } from "./useOrder " ;
1110
1211/**
1312 * @author Aloento
@@ -24,19 +23,17 @@ const useStyles = makeStyles({
2423/**
2524 * @author Aloento
2625 * @since 0.5.0
27- * @version 1.2 .0
26+ * @version 1.3 .0
2827 */
29- export function CommentAppend ( { OrderId, Refresh, Admin, ParentLog } : IOrderRef ) {
28+ export function CommentAppend ( { OrderId, Refresh, Admin, ParentLog } : IOrderComp & { Refresh : ( ) => void } ) {
3029 const log = useConst ( ( ) => ParentLog . With ( "Append" ) ) ;
3130
3231 const style = useStyles ( ) ;
3332 const [ cmt , setCmt ] = useState < string > ( ) ;
3433
3534 const { dispatch, dispatchToast } = useErrorToast ( log ) ;
3635
37- const hub = ( Admin ? AdminHub : Hub ) . Order . Post as typeof AdminHub . Order . Post & typeof Hub . Order . Post ;
38-
39- const { run : append } = hub . useAppend ( {
36+ const { run : append , loading } = ( Admin ? AdminHub : Hub ) . Order . Post . useAppend ( {
4037 manual : true ,
4138 onError ( e , req ) {
4239 dispatch ( {
@@ -54,10 +51,13 @@ export function CommentAppend({ OrderId, Refresh, Admin, ParentLog }: IOrderRef)
5451 ) ;
5552
5653 Refresh ( ) ;
54+ setCmt ( "" ) ;
5755 }
5856 } ) ;
5957
60- const { run : cancel } = ( Admin ? hub . useClose : hub . useCancel ) ( {
58+ const { data : order , mutate } = useOrder ( OrderId , Admin ) ;
59+
60+ const { run : cancel , loading : submit } = ( Admin ? AdminHub : Hub ) . Order . Post . useCancel ( {
6161 manual : true ,
6262 onError ( e , params ) {
6363 dispatch ( {
@@ -66,26 +66,21 @@ export function CommentAppend({ OrderId, Refresh, Admin, ParentLog }: IOrderRef)
6666 Error : e
6767 } ) ;
6868 } ,
69- onSuccess ( ) {
69+ onSuccess ( data ) {
7070 dispatchToast (
7171 < Toast >
7272 < ToastTitle > Order { Admin ? "Closed" : "Cancelled" } </ ToastTitle >
7373 </ Toast > ,
7474 { intent : "success" }
7575 ) ;
7676
77- Refresh ( ) ;
77+ mutate ( ( old ) => ( {
78+ ...old ! ,
79+ Status : data
80+ } ) ) ;
7881 }
7982 } ) ;
8083
81- const index = useConst ( ( ) => SignalR . Index ( OrderId , Hub . Order . Get . order ) ) ;
82-
83- const { data : order } = useSWR (
84- index ,
85- ( ) => ( Admin ? AdminHub : Hub ) . Order . Get . Order ( OrderId ) ,
86- { useMemory : true }
87- ) ;
88-
8984 switch ( order ?. Status ) {
9085 case "Cancelled" :
9186 case "Finished" :
@@ -100,7 +95,10 @@ export function CommentAppend({ OrderId, Refresh, Admin, ParentLog }: IOrderRef)
10095 < div className = { style . body } >
10196 {
10297 ! ( order ?. Status === "Finished" || order ?. Status === "Returning" ) &&
103- < Button onClick = { ( ) => cancel ( OrderId , cmt ! ) } >
98+ < Button
99+ onClick = { ( ) => cancel ( OrderId , cmt ! ) }
100+ disabled = { submit }
101+ >
104102 {
105103 Admin
106104 ? "Force Close"
@@ -109,7 +107,11 @@ export function CommentAppend({ OrderId, Refresh, Admin, ParentLog }: IOrderRef)
109107 </ Button >
110108 }
111109
112- < Button appearance = "primary" onClick = { ( ) => append ( OrderId , cmt ! ) } >
110+ < Button
111+ appearance = "primary"
112+ onClick = { ( ) => append ( OrderId , cmt ! ) }
113+ disabled = { loading }
114+ >
113115 Add Comment
114116 </ Button >
115117 </ div >
0 commit comments