mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 15:26:02 +00:00
fix: action loading, refresh context, form submit and validate (#523)
This commit is contained in:
parent
88dc2db0f2
commit
a8ce758cab
@ -223,17 +223,20 @@ export const useCustomizeRequestActionProps = () => {
|
||||
const compile = useCompile();
|
||||
const form = useForm();
|
||||
const { fields, getField } = useCollection();
|
||||
const { field, resource } = useBlockRequestContext();
|
||||
const { field, resource, __parent, service } = useBlockRequestContext();
|
||||
const currentRecord = useRecord();
|
||||
const currentUserContext = useCurrentUserContext();
|
||||
const currentUser = currentUserContext?.data?.data;
|
||||
const actionField = useField();
|
||||
|
||||
return {
|
||||
async onClick() {
|
||||
const { skipValidator, onSuccess, requestSettings } = actionSchema?.['x-action-settings'] ?? {};
|
||||
const xAction = actionSchema?.['x-action'];
|
||||
if (!requestSettings['url']) {
|
||||
return;
|
||||
}
|
||||
if (skipValidator === false) {
|
||||
if (skipValidator === false && xAction === 'customize:form:request') {
|
||||
await form.submit();
|
||||
}
|
||||
|
||||
@ -241,7 +244,7 @@ export const useCustomizeRequestActionProps = () => {
|
||||
const params = requestSettings['params'] ? JSON.parse(requestSettings['params']) : {};
|
||||
const data = requestSettings['data'] ? JSON.parse(requestSettings['data']) : {};
|
||||
const methods = ['POST', 'PUT', 'PATCH'];
|
||||
if (actionSchema['x-action'] === 'customize:form:request' && methods.includes(requestSettings['method'])) {
|
||||
if (xAction === 'customize:form:request' && methods.includes(requestSettings['method'])) {
|
||||
const fieldNames = fields.map((field) => field.name);
|
||||
const values = getFormValues(filterByTk, field, form, fieldNames, getField, resource);
|
||||
Object.assign(data, values);
|
||||
@ -253,10 +256,18 @@ export const useCustomizeRequestActionProps = () => {
|
||||
params: SchemaCompiler.compile(params, { currentRecord, currentUser }),
|
||||
data: SchemaCompiler.compile(data, { currentRecord, currentUser }),
|
||||
};
|
||||
|
||||
actionField.data = field.data || {};
|
||||
actionField.data.loading = true;
|
||||
try {
|
||||
await apiClient.request({
|
||||
...requestBody,
|
||||
});
|
||||
actionField.data.loading = false;
|
||||
|
||||
service?.refresh?.();
|
||||
if (!(resource instanceof TableFieldResource)) {
|
||||
__parent?.service?.refresh?.();
|
||||
}
|
||||
|
||||
if (!onSuccess?.successMessage) {
|
||||
return;
|
||||
@ -277,6 +288,9 @@ export const useCustomizeRequestActionProps = () => {
|
||||
} else {
|
||||
message.success(compile(onSuccess?.successMessage));
|
||||
}
|
||||
} finally {
|
||||
actionField.data.loading = false;
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
@ -112,6 +112,7 @@ export const FormActionInitializers = {
|
||||
'x-designer': 'Action.Designer',
|
||||
'x-action-settings': {
|
||||
requestSettings: {},
|
||||
skipValidator: false,
|
||||
onSuccess: {
|
||||
manualClose: false,
|
||||
redirecting: false,
|
||||
@ -241,6 +242,7 @@ export const CreateFormActionInitializers = {
|
||||
'x-designer': 'Action.Designer',
|
||||
'x-action-settings': {
|
||||
requestSettings: {},
|
||||
skipValidator: false,
|
||||
onSuccess: {
|
||||
manualClose: false,
|
||||
redirecting: false,
|
||||
@ -370,6 +372,7 @@ export const UpdateFormActionInitializers = {
|
||||
'x-designer': 'Action.Designer',
|
||||
'x-action-settings': {
|
||||
requestSettings: {},
|
||||
skipValidator: false,
|
||||
onSuccess: {
|
||||
manualClose: false,
|
||||
redirecting: false,
|
||||
|
@ -124,6 +124,7 @@ export const ReadPrettyFormActionInitializers = {
|
||||
'x-designer': 'Action.Designer',
|
||||
'x-action-settings': {
|
||||
requestSettings: {},
|
||||
skipValidator: false,
|
||||
onSuccess: {
|
||||
manualClose: false,
|
||||
redirecting: false,
|
||||
|
Loading…
Reference in New Issue
Block a user