Skip to content

Commit 38e770c

Browse files
kamalqureshiraheeliftikhar5
authored andcommitted
Sharing App Permissions
1 parent 8afeae1 commit 38e770c

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { message } from "antd";
22
import { ActionConfig, ActionExecuteParams } from "../types";
33
import ApplicationApi from "api/applicationApi";
4-
import { getApplicationIdInReducer } from "comps/utils/reduceContext";
54
import { executeQueryAction } from "lowcoder-core";
65
import { getPromiseAfterDispatch } from "util/promiseUtils";
76
import { runScript } from "../utils";
8-
7+
import { updateAppPermissionInfo } from "redux/reduxActions/applicationActions";
8+
import { reduxStore } from "redux/store/store";
99

1010
export const configureAppMetaAction: ActionConfig = {
1111
key: 'configure-app-meta',
@@ -56,10 +56,12 @@ export const publishAppAction: ActionConfig = {
5656
label: 'Publish app',
5757
category: 'app-configuration',
5858
requiresInput: false,
59-
execute: async () => {
59+
execute: async (params: ActionExecuteParams) => {
60+
const { editorState } = params;
61+
const applicationIdEditor = editorState.rootComp.preloadId;
62+
const applicationId = applicationIdEditor.replace('app-', '');
63+
6064
try {
61-
const applicationId = getApplicationIdInReducer();
62-
6365
if (!applicationId) {
6466
message.error('Application ID not found');
6567
return;
@@ -86,9 +88,50 @@ export const shareAppAction: ActionConfig = {
8688
label: 'Share app',
8789
category: 'app-configuration',
8890
requiresInput: false,
89-
execute: async () => {
90-
// TODO: Implement share app
91-
console.log('Share app');
91+
execute: async (params: ActionExecuteParams) => {
92+
// TODO: Get app sharing from the user
93+
const appSharing = {
94+
public: true,
95+
publishMarketplace: false
96+
}
97+
98+
const { editorState } = params;
99+
const applicationIdEditor = editorState.rootComp.preloadId;
100+
const applicationId = applicationIdEditor.replace('app-', '');
101+
102+
if (!applicationId) {
103+
message.error('Application ID not found');
104+
return;
105+
}
106+
107+
try {
108+
// Update Application Sharig Status
109+
// Update Redux state to reflect the public change in UI
110+
const publicResponse = await ApplicationApi.publicToAll(applicationId, appSharing.public);
111+
112+
if (publicResponse.data.success) {
113+
reduxStore.dispatch(updateAppPermissionInfo({ publicToAll: appSharing.public }));
114+
message.success('Application is now public!');
115+
116+
// Update Application Marketplace Sharing Status
117+
try {
118+
const marketplaceResponse = await ApplicationApi.publicToMarketplace(applicationId, appSharing.publishMarketplace);
119+
if (marketplaceResponse.data.success) {
120+
reduxStore.dispatch(updateAppPermissionInfo({ publicToMarketplace: appSharing.publishMarketplace }));
121+
message.success(`Application ${appSharing.publishMarketplace ? 'published to' : 'unpublished from'} marketplace successfully!`);
122+
}
123+
} catch (marketplaceError) {
124+
console.error(`Error ${appSharing.publishMarketplace ? 'publishing to' : 'unpublishing from'} marketplace:`, marketplaceError);
125+
message.warning(`Application is public but ${appSharing.publishMarketplace ? 'publishing to' : 'unpublishing from'} marketplace failed`);
126+
}
127+
128+
} else {
129+
message.error('Failed to make application public');
130+
}
131+
} catch (publicError) {
132+
console.error('Error making application public:', publicError);
133+
message.error('Failed to make application public');
134+
}
92135
}
93136
};
94137

0 commit comments

Comments
 (0)