Skip to content

Commit f9354e7

Browse files
committed
fix: 🐛 ShadowModal button loading state
1 parent 2a22135 commit f9354e7

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

src/pro-array-table/mixin.pro.tsx

+17-16
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export const Flex = (
3434
start?: boolean;
3535
end?: boolean;
3636
} & Pick<React.CSSProperties, "marginTop" | "marginBottom">
37-
>,
37+
>
3838
) => {
3939
const justifyContent = Object.keys(props).find((key) =>
40-
justifyContentList.find((prop) => new RegExp(key).test(prop)),
40+
justifyContentList.find((prop) => new RegExp(key).test(prop))
4141
);
4242

4343
return props.hidden ? null : (
@@ -110,7 +110,7 @@ export const RowSelectionPro = (props: {
110110
m[i] = true;
111111
return m;
112112
},
113-
{},
113+
{}
114114
);
115115
const keys: (string | number)[] = [];
116116
ds.forEach((item) => {
@@ -135,12 +135,12 @@ export interface CommonShadowPopup extends IShadowFormOptions {
135135
act?: string;
136136
onCancel?: (
137137
ctx: ReturnType<typeof useProArrayTableContext>,
138-
querylistCtx: ReturnType<typeof useQueryListContext>,
138+
querylistCtx: ReturnType<typeof useQueryListContext>
139139
) => void | Promise<void>;
140140
onOk?: (
141141
data: any,
142142
ctx: ReturnType<typeof useProArrayTableContext>,
143-
querylistCtx: ReturnType<typeof useQueryListContext>,
143+
querylistCtx: ReturnType<typeof useQueryListContext>
144144
) => void | Promise<void>;
145145
}
146146

@@ -149,7 +149,7 @@ export const ArrayTableShowModal: React.FC<
149149
CommonShadowPopup
150150
> = (props) => {
151151
const { SchemaField, form, schema } = useShadowForm(
152-
pick(props, "schema", "schemaFieldOptions", "subFormOptions"),
152+
pick(props, "schema", "schemaFieldOptions", "subFormOptions")
153153
);
154154
const mySchema = useFieldSchema();
155155
const act = props.act ?? mySchema.name;
@@ -189,7 +189,6 @@ export const ArrayTableShowModal: React.FC<
189189
}, 200);
190190
}).finally(() => {
191191
pending.current = false;
192-
setLoading(false);
193192
});
194193
};
195194

@@ -201,9 +200,11 @@ export const ArrayTableShowModal: React.FC<
201200
onCancel={() => {
202201
if (pending.current) return;
203202
setLoading(true);
204-
return Promise.resolve(props?.onCancel?.(ctx, queryListCtx)).then(() =>
205-
reset(),
206-
);
203+
return Promise.resolve(props?.onCancel?.(ctx, queryListCtx))
204+
.then(() => reset())
205+
.finally(() => {
206+
setLoading(false);
207+
});
207208
}}
208209
cancelButtonProps={{
209210
loading,
@@ -218,13 +219,13 @@ export const ArrayTableShowModal: React.FC<
218219
return form
219220
.submit()
220221
.then((data) => {
221-
return Promise.resolve(
222-
props?.onOk?.(data, ctx, queryListCtx),
223-
).finally(() => {
224-
pending.current = false;
225-
});
222+
return Promise.resolve(props?.onOk?.(data, ctx, queryListCtx));
226223
})
227-
.then(() => reset());
224+
.then(() => reset())
225+
.finally(() => {
226+
pending.current = false;
227+
setLoading(false);
228+
});
228229
}}
229230
>
230231
<FormProvider form={form}>

src/shadow-form/modal.tsx

+17-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const ShadowModal: React.FC<
2626
const [visible, setVisible] = useState(false);
2727
const pending = useRef(false);
2828
const navRef = useRef<HTMLSpanElement>(null);
29+
const [loading, setLoading] = useState(false);
2930

3031
const init = (c = 0) => {
3132
if (!form) {
@@ -42,7 +43,7 @@ export const ShadowModal: React.FC<
4243
return Promise.resolve(initLoader.current(field.record)).then(
4344
(init) => {
4445
form?.setValues(toJS(init || {}));
45-
},
46+
}
4647
);
4748
} else {
4849
return Promise.resolve(form?.setValues(toJS(field.record)));
@@ -87,19 +88,31 @@ export const ShadowModal: React.FC<
8788
<Modal
8889
{...props}
8990
open={visible}
91+
okButtonProps={{
92+
loading,
93+
}}
94+
cancelButtonProps={{ loading }}
9095
onCancel={(e: any) => {
9196
if (pending.current) return;
97+
setLoading(true);
9298
return form
9399
?.reset()
94100
.then(() => props?.onCancel?.(e))
95-
.then(() => reset());
101+
.then(() => reset())
102+
.finally(() => {
103+
setLoading(false);
104+
});
96105
}}
97106
onOk={() => {
98107
if (pending.current) return;
108+
setLoading(true);
99109
return form
100110
?.submit()
101111
.then((data: any) => props?.onOk?.(data))
102-
.then(() => reset());
112+
.then(() => reset())
113+
.finally(() => {
114+
setLoading(false);
115+
});
103116
}}
104117
>
105118
<FormProvider form={form}>
@@ -122,5 +135,5 @@ export const ShadowModal: React.FC<
122135
)}
123136
</React.Fragment>
124137
);
125-
},
138+
}
126139
);

0 commit comments

Comments
 (0)