Skip to content

Commit 98347d3

Browse files
author
Bogdan Tsechoev
committed
Merge branch 'fix-private-select' into 'master'
Assistant: Priveleged until check added See merge request postgres-ai/database-lab!936
2 parents da016ea + 35c2cf3 commit 98347d3

File tree

5 files changed

+8
-59
lines changed

5 files changed

+8
-59
lines changed

ui/packages/platform/src/components/BotSettingsForm/BotSettingsForm.tsx

+2-22
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,8 @@ const BotSettingsForm: React.FC<BotSettingsFormProps> = (props) => {
126126

127127
const classes = useStyles()
128128

129-
const [threadVisibility, setThreadVisibility] = useState('private')
130129
const [data, setData] = useState<BotSettingState['data'] | null>(null)
131130

132-
const isSubscriber = useMemo(() => {
133-
const hasEEPlan = orgData?.data?.plan === 'EE';
134-
const hasSEPlan = data?.dbLabInstances?.data
135-
? Object.values(data.dbLabInstances.data).some((item) => item.plan === "SE")
136-
: false;
137-
138-
return hasEEPlan || hasSEPlan;
139-
}, [data?.dbLabInstances?.data, orgData?.data?.plan]);
140-
141131

142132
useEffect(() => {
143133
const unsubscribe = Store.listen(function () {
@@ -146,8 +136,6 @@ const BotSettingsForm: React.FC<BotSettingsFormProps> = (props) => {
146136
if (JSON.stringify(newStoreData) !== JSON.stringify(data)) {
147137
const auth = newStoreData?.auth || null;
148138
const orgProfile = newStoreData?.orgProfile || null;
149-
const dbLabInstances = newStoreData?.dbLabInstances || null;
150-
const projectId = props.match?.params?.projectId || null;
151139

152140
if (
153141
auth?.token &&
@@ -158,14 +146,6 @@ const BotSettingsForm: React.FC<BotSettingsFormProps> = (props) => {
158146
Actions.getOrgs(auth.token, orgId);
159147
}
160148

161-
if (
162-
auth?.token &&
163-
!dbLabInstances?.isProcessing &&
164-
!dbLabInstances?.error
165-
) {
166-
Actions.getDbLabInstances(auth.token, orgId, projectId);
167-
}
168-
169149
setData(newStoreData);
170150
}
171151
});
@@ -269,13 +249,13 @@ const BotSettingsForm: React.FC<BotSettingsFormProps> = (props) => {
269249
label={<><b>Public:</b> anyone can view chats, but only team members can respond</>}
270250
/>
271251
<FormControlLabel
272-
disabled={!isSubscriber}
252+
disabled={!orgData?.chats_private_allowed}
273253
className={classes.formControlLabel}
274254
value="private"
275255
control={<Radio size="small"/>}
276256
label={<><b>Private:</b> chats are visible only to members of your organization</>}
277257
/>
278-
{!isSubscriber && <Typography variant="body2" className={classes.unlockNote}>
258+
{!orgData?.chats_private_allowed && <Typography variant="body2" className={classes.unlockNote}>
279259
Unlock private conversations by either:
280260
<ol>
281261
<li>

ui/packages/platform/src/components/BotSettingsForm/BotSettingsFormWrapper.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export interface BotSettingsFormProps {
1010
settingsOrganizationUpdate?: boolean
1111
}
1212
orgData?: {
13+
priveleged_until: Date
14+
chats_private_allowed: boolean
1315
data?: {
1416
plan?: string
1517
} | null

ui/packages/platform/src/components/types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface Orgs {
3939
id: number
4040
owner_user_id: number
4141
is_chat_public_by_default: boolean
42+
chats_private_allowed: boolean
4243
data: {
4344
plan: string
4445
} | null

ui/packages/platform/src/pages/Bot/BotWrapper.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export interface BotWrapperProps {
1313
orgData: {
1414
id: number,
1515
is_chat_public_by_default: boolean
16+
priveleged_until: Date
17+
chats_private_allowed: boolean
1618
data: {
1719
plan: string
1820
} | null

ui/packages/platform/src/pages/Bot/index.tsx

+1-37
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ export const BotPage = (props: BotPageProps) => {
129129
const [isChatsListVisible, setChatsListVisible] = useState(window?.innerWidth > 640);
130130
const [isSettingsDialogVisible, setSettingsDialogVisible] = useState(false);
131131
const [isDebugConsoleVisible, setDebugConsoleVisible] = useState(false);
132-
const [refluxData, setRefluxData] = useState<RefluxState>(null)
133132

134133
const history = useHistory();
135134

@@ -177,42 +176,7 @@ export const BotPage = (props: BotPageProps) => {
177176
}
178177
}
179178

180-
const isSubscriber = useMemo(() => {
181-
const hasEEPlan = orgData?.data?.plan === 'EE';
182-
const hasSEPlan = refluxData?.dbLabInstances?.data
183-
? Object.values(refluxData.dbLabInstances.data).some((item) => item.plan === "SE")
184-
: false;
185-
186-
return hasEEPlan || hasSEPlan;
187-
}, [refluxData?.dbLabInstances?.data, orgData?.data?.plan]);
188-
189-
useEffect(() => {
190-
const unsubscribe = Store.listen(function () {
191-
const newStoreData = this.data;
192-
193-
if (JSON.stringify(newStoreData) !== JSON.stringify(refluxData)) {
194-
const auth = newStoreData?.auth || null;
195-
const dbLabInstances = newStoreData?.dbLabInstances || null;
196-
const projectId = props.match?.params?.projectId || null;
197-
198-
if (
199-
auth?.token &&
200-
!dbLabInstances?.isProcessing &&
201-
!dbLabInstances?.error
202-
) {
203-
Actions.getDbLabInstances(auth.token, orgId, projectId);
204-
}
205-
206-
setRefluxData(newStoreData);
207-
}
208-
});
209-
210-
Actions.refresh();
211-
212-
return () => {
213-
unsubscribe();
214-
};
215-
}, [orgId, refluxData, props.match.params.projectId]);
179+
const isSubscriber = useMemo(() => orgData?.chats_private_allowed, [orgData?.chats_private_allowed]);
216180

217181
const publicChatMessage = useMemo(() => {
218182
if (isDemoOrg) {

0 commit comments

Comments
 (0)