Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
chenos committed Aug 23, 2024
1 parent dac2da0 commit b361b79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/client/PublicSharedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function PublicAPIClientProvider({ children }) {
const apiClient = new APIClient(app.getOptions().apiClient as any);
apiClient.app = app;
apiClient.axios.interceptors.request.use((config) => {
config.headers['X-Form-Token'] = apiClient.storage.getItem('NOCOBASE_FORM_TOKEN');
config.headers['X-Form-Token'] = apiClient.storage.getItem('NOCOBASE_FORM_TOKEN') || '';
return config;
});
return apiClient;
Expand All @@ -68,7 +68,7 @@ function InternalSharedForm() {
{
onSuccess(data) {
apiClient.axios.interceptors.request.use((config) => {
config.headers['X-Form-Token'] = data?.data?.token;
config.headers['X-Form-Token'] = data?.data?.token || '';
return config;
});
},
Expand Down
21 changes: 5 additions & 16 deletions src/client/useCreateActionProps.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import { useForm } from '@formily/react';
import { useActionContext, useCollection, useDataBlockRequest, useDataBlockResource } from '@nocobase/client';
import { useDataBlockResource } from '@nocobase/client';
import { App as AntdApp } from 'antd';

export const useCreateActionProps = () => {
const { setVisible } = useActionContext();
const { message } = AntdApp.useApp();
const form = useForm();
const resource = useDataBlockResource();
const { runAsync } = useDataBlockRequest();
const collection = useCollection();
return {
type: 'primary',
async onClick() {
await form.submit();
const values = form.values;
if (values[collection.filterTargetKey]) {
await resource.update({
values,
filterByTk: values[collection.filterTargetKey],
});
} else {
await resource.publicSubmit({
values,
});
}
await runAsync();
await resource.publicSubmit({
values,
});
await form.reset();
message.success('Saved successfully!');
setVisible(false);
},
};
};
8 changes: 7 additions & 1 deletion src/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,17 @@ export class PluginSharedFormsServer extends Plugin {
if (!ctx.action) {
return next();
}
const { actionName, resourceName, params } = ctx.action;
// 有密码时,跳过 token
if (resourceName === 'sharedForms' && actionName === 'getMeta' && params.password) {
return next();
}
const jwt = this.app.authManager.jwt;
const token = ctx.get('X-Form-Token');
if (token) {
try {
ctx.sharedForm = await jwt.decode(token);
// TODO:decode token
ctx.sharedForm = {};
// 将 publicSubmit 转为 create(用于触发工作流的 Action 事件)
const actionName = ctx.action.actionName;
if (actionName === 'publicSubmit') {
Expand Down

0 comments on commit b361b79

Please sign in to comment.