larxius commited on
Commit
aee661c
·
verified ·
1 Parent(s): 70eea48

Update frontend/src/pages/SuperAdminPanel.jsx

Browse files
frontend/src/pages/SuperAdminPanel.jsx CHANGED
@@ -436,14 +436,26 @@ const SuperAdminPanel = () => {
436
  };
437
 
438
  const handleProvisionTenant = () => {
439
- setPromptValues({ tier: 'free' });
440
  setPromptModal({
441
  isOpen: true,
442
  title: 'Add New Organization',
443
  desc: 'Create a new tenant organization.',
444
  inputs: [
445
  { key: 'name', label: 'Organization Name', placeholder: 'Enter name...' },
446
- { key: 'tier', label: 'Subscription Tier', placeholder: 'free, quick, standard, advanced, enterprise' }
 
 
 
 
 
 
 
 
 
 
 
 
447
  ],
448
  onConfirm: async (values) => {
449
  try {
@@ -452,8 +464,15 @@ const SuperAdminPanel = () => {
452
  headers: { 'Authorization': `Bearer ${localStorage.getItem('wss_token')}`, 'Content-Type': 'application/json' },
453
  body: JSON.stringify({ name: values.name, tier: values.tier })
454
  });
455
- if (res.ok) fetchStats();
456
- } catch (err) { }
 
 
 
 
 
 
 
457
  closePrompt();
458
  }
459
  });
@@ -524,14 +543,31 @@ const SuperAdminPanel = () => {
524
  };
525
 
526
  const handleEditTenant = (org) => {
527
- setPromptValues({ name: org.name, tier: org.tier.toLowerCase() });
 
 
 
 
 
528
  setPromptModal({
529
  isOpen: true,
530
  title: 'Edit Organization',
531
  desc: `Modify settings for ${org.name}`,
532
  inputs: [
533
- { key: 'name', label: 'Organization Name' },
534
- { key: 'tier', label: 'Subscription Tier' }
 
 
 
 
 
 
 
 
 
 
 
 
535
  ],
536
  onConfirm: async (values) => {
537
  try {
@@ -540,8 +576,15 @@ const SuperAdminPanel = () => {
540
  headers: { 'Authorization': `Bearer ${localStorage.getItem('wss_token')}`, 'Content-Type': 'application/json' },
541
  body: JSON.stringify({ name: values.name, tier: values.tier })
542
  });
543
- if (res.ok) fetchStats();
544
- } catch (err) { }
 
 
 
 
 
 
 
545
  closePrompt();
546
  }
547
  });
@@ -1359,7 +1402,11 @@ const SuperAdminPanel = () => {
1359
  onChange={(e) => handlePromptChange(input.key, e.target.value)}
1360
  className="bg-surface-container border border-outline-variant rounded-lg px-3 py-2 focus:border-primary outline-none text-on-surface"
1361
  >
1362
- {input.options.map(opt => <option key={opt} value={opt}>{opt}</option>)}
 
 
 
 
1363
  </select>
1364
  ) : (
1365
  <input
 
436
  };
437
 
438
  const handleProvisionTenant = () => {
439
+ setPromptValues({ tier: 'free', name: '' });
440
  setPromptModal({
441
  isOpen: true,
442
  title: 'Add New Organization',
443
  desc: 'Create a new tenant organization.',
444
  inputs: [
445
  { key: 'name', label: 'Organization Name', placeholder: 'Enter name...' },
446
+ {
447
+ key: 'tier',
448
+ label: 'Subscription Tier',
449
+ type: 'select',
450
+ options: [
451
+ { label: 'Free', value: 'free' },
452
+ { label: 'Quick', value: 'quick' },
453
+ { label: 'Standard', value: 'standard' },
454
+ { label: 'Advanced', value: 'advanced' },
455
+ { label: 'Enterprise', value: 'enterprise' },
456
+ { label: 'Enterprise(Custom)', value: 'Enterprise(Custom)' }
457
+ ]
458
+ }
459
  ],
460
  onConfirm: async (values) => {
461
  try {
 
464
  headers: { 'Authorization': `Bearer ${localStorage.getItem('wss_token')}`, 'Content-Type': 'application/json' },
465
  body: JSON.stringify({ name: values.name, tier: values.tier })
466
  });
467
+ if (res.ok) {
468
+ toast.success('Organization created successfully');
469
+ fetchStats();
470
+ } else {
471
+ toast.error('Failed to create organization');
472
+ }
473
+ } catch (err) {
474
+ toast.error('Network error creating organization');
475
+ }
476
  closePrompt();
477
  }
478
  });
 
543
  };
544
 
545
  const handleEditTenant = (org) => {
546
+ const rawTier = (org.tier || org.subscription_tier || 'free');
547
+ const isCustom = rawTier.toLowerCase().includes('custom');
548
+ setPromptValues({
549
+ name: org.name,
550
+ tier: isCustom ? 'Enterprise(Custom)' : rawTier.toLowerCase()
551
+ });
552
  setPromptModal({
553
  isOpen: true,
554
  title: 'Edit Organization',
555
  desc: `Modify settings for ${org.name}`,
556
  inputs: [
557
+ { key: 'name', label: 'Organization Name', placeholder: 'Enter organization name...' },
558
+ {
559
+ key: 'tier',
560
+ label: 'Subscription Tier',
561
+ type: 'select',
562
+ options: [
563
+ { label: 'Free', value: 'free' },
564
+ { label: 'Quick', value: 'quick' },
565
+ { label: 'Standard', value: 'standard' },
566
+ { label: 'Advanced', value: 'advanced' },
567
+ { label: 'Enterprise', value: 'enterprise' },
568
+ { label: 'Enterprise(Custom)', value: 'Enterprise(Custom)' }
569
+ ]
570
+ }
571
  ],
572
  onConfirm: async (values) => {
573
  try {
 
576
  headers: { 'Authorization': `Bearer ${localStorage.getItem('wss_token')}`, 'Content-Type': 'application/json' },
577
  body: JSON.stringify({ name: values.name, tier: values.tier })
578
  });
579
+ if (res.ok) {
580
+ toast.success('Organization updated successfully');
581
+ fetchStats();
582
+ } else {
583
+ toast.error('Failed to update organization');
584
+ }
585
+ } catch (err) {
586
+ toast.error('Network error updating organization');
587
+ }
588
  closePrompt();
589
  }
590
  });
 
1402
  onChange={(e) => handlePromptChange(input.key, e.target.value)}
1403
  className="bg-surface-container border border-outline-variant rounded-lg px-3 py-2 focus:border-primary outline-none text-on-surface"
1404
  >
1405
+ {input.options.map(opt => {
1406
+ const val = typeof opt === 'object' ? opt.value : opt;
1407
+ const lbl = typeof opt === 'object' ? opt.label : opt;
1408
+ return <option key={val} value={val}>{lbl}</option>;
1409
+ })}
1410
  </select>
1411
  ) : (
1412
  <input