@greatapps/common 1.1.356 → 1.1.358

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/common",
3
- "version": "1.1.356",
3
+ "version": "1.1.358",
4
4
  "description": "Shared library for GreatApps frontend applications",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./src/index.ts",
@@ -11,6 +11,8 @@ import { SecuritySection } from './sections/SecuritySection';
11
11
  import useConfigurationsModal from './hooks/useConfigurationsModal';
12
12
  import useIsMobile from '../../hooks/useIsMobile';
13
13
  import { useAccountModals } from '../../store/useAccountModals';
14
+ import { useAuth } from '../../providers/auth.provider';
15
+ import { UserProfile } from '../../modules/users/schema';
14
16
 
15
17
  export default function ConfigurationsMyAccountModal() {
16
18
  const {
@@ -24,6 +26,8 @@ export default function ConfigurationsMyAccountModal() {
24
26
  const open = activeModal === 'configurations';
25
27
  const { hasActiveSubscription } = config;
26
28
 
29
+ const { user } = useAuth();
30
+ const isOwnerOrAdmin = user?.profile === UserProfile.owner || user?.profile === UserProfile.admin;
27
31
  const isMobile = useIsMobile();
28
32
  const { activeSection, setActiveSection } = useConfigurationsModal({
29
33
  isOpen: open,
@@ -105,10 +109,12 @@ export default function ConfigurationsMyAccountModal() {
105
109
  <span className="paragraph-small-medium">Preferências</span>
106
110
  </TabsTrigger>
107
111
 
108
- <TabsTrigger value={AccountSectionType.SECURITY} className={tabTriggerClasses}>
109
- <IconLock size={20} className="shrink-0" />
110
- <span className="paragraph-small-medium">Segurança</span>
111
- </TabsTrigger>
112
+ {isOwnerOrAdmin && (
113
+ <TabsTrigger value={AccountSectionType.SECURITY} className={tabTriggerClasses}>
114
+ <IconLock size={20} className="shrink-0" />
115
+ <span className="paragraph-small-medium">Segurança</span>
116
+ </TabsTrigger>
117
+ )}
112
118
  </div>
113
119
  </TabsList>
114
120
 
@@ -117,17 +123,21 @@ export default function ConfigurationsMyAccountModal() {
117
123
  <PreferencesSection onClose={close} />
118
124
  </TabsContent>
119
125
 
120
- <TabsContent value={AccountSectionType.SECURITY} className="h-full! relative overflow-hidden">
121
- <SecuritySection
122
- setActiveSection={setActiveSection}
123
- onClose={close}
124
- onDeleteAccount={handleDeleteAccount}
125
- />
126
- </TabsContent>
127
-
128
- <TabsContent value={AccountSectionType.CHANGE_PASSWORD} className="h-full! relative overflow-hidden">
129
- <ChangePasswordSection onBack={() => setActiveSection(AccountSectionType.SECURITY)} />
130
- </TabsContent>
126
+ {isOwnerOrAdmin && (
127
+ <>
128
+ <TabsContent value={AccountSectionType.SECURITY} className="h-full! relative overflow-hidden">
129
+ <SecuritySection
130
+ setActiveSection={setActiveSection}
131
+ onClose={close}
132
+ onDeleteAccount={handleDeleteAccount}
133
+ />
134
+ </TabsContent>
135
+
136
+ <TabsContent value={AccountSectionType.CHANGE_PASSWORD} className="h-full! relative overflow-hidden">
137
+ <ChangePasswordSection onBack={() => setActiveSection(AccountSectionType.SECURITY)} />
138
+ </TabsContent>
139
+ </>
140
+ )}
131
141
  </div>
132
142
  </Tabs>
133
143
  </DialogContent>
@@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
4
4
  import { useForm } from 'react-hook-form';
5
5
  import { toast } from 'sonner';
6
6
  import { IconLock } from '@tabler/icons-react';
7
+ import { cn } from '../../../infra/utils/clsx';
7
8
  import { Button } from '../../ui/buttons/Button';
8
9
  import { Separator } from '../../ui/data-display/Separator';
9
10
  import { Toast } from '../../ui/feedback/Toast';
@@ -43,8 +44,8 @@ export function PreferencesSection({ onClose }: PreferencesSectionProps) {
43
44
  const { data: timezones = [] } = useTimezones();
44
45
  const { data: currencies = [] } = useCurrencies();
45
46
  const { user, account } = useAuth();
46
- const canEditPreferences =
47
- user?.profile === UserProfile.owner || user?.profile === UserProfile.admin;
47
+ const isOwner = user?.profile === UserProfile.owner;
48
+ const canEditPreferences = isOwner || user?.profile === UserProfile.admin;
48
49
  const updateAccountUser = useUpdateAccountUser();
49
50
  const updateAccount = useUpdateAccount();
50
51
  const [confirmGlobalOpen, setConfirmGlobalOpen] = useState(false);
@@ -116,7 +117,7 @@ export function PreferencesSection({ onClose }: PreferencesSectionProps) {
116
117
 
117
118
  const onSubmit = (data: PreferencesFormValues) => {
118
119
  const accountFields: UpdateAccountRequest = {
119
- ...(canEditPreferences && dirtyFields.companyName && { name: data.companyName }),
120
+ ...(isOwner && dirtyFields.companyName && { name: data.companyName }),
120
121
  ...(canEditPreferences && dirtyFields.currency && { currency: data.currency }),
121
122
  ...(canEditPreferences && dirtyFields.timezone && { timezone: data.timezone }),
122
123
  };
@@ -153,10 +154,10 @@ export function PreferencesSection({ onClose }: PreferencesSectionProps) {
153
154
  <FormField
154
155
  label="Nome da empresa"
155
156
  placeholder="Digite o nome da empresa"
156
- classnameContainer="w-full"
157
+ classnameContainer={cn('w-full', !isOwner && 'cursor-not-allowed opacity-50')}
157
158
  value={watch('companyName')}
158
159
  onChange={(e) => setValue('companyName', e.target.value, { shouldDirty: true })}
159
- disabled={!canEditPreferences}
160
+ disabled={!isOwner}
160
161
  />
161
162
  </div>
162
163
 
@@ -125,7 +125,7 @@ class ApiClient {
125
125
 
126
126
  if (!response.ok) {
127
127
  const errBody = await response.text();
128
- let message = `HTTP error ${response.status}`;
128
+ let message = `HTTP error ${response.status} ${response.statusText} ${errBody}`;
129
129
  let code = "HTTP_ERROR";
130
130
  try {
131
131
  const errorData = JSON.parse(errBody) as Record<string, unknown>;
@@ -10,6 +10,9 @@ import type {
10
10
  UpdateAccountUserRequest,
11
11
  } from '../types';
12
12
  import { twoFactorService } from '../services/two-factor.service';
13
+ import { findUserById } from '../../users/action/find-user-by-id.action';
14
+ import { UserProfile } from '../../users/schema';
15
+ import { ApiError } from '../../../infra/api/types';
13
16
 
14
17
  export async function listAccountUsersAction(params?: AccountUsersPaginationParams) {
15
18
  return safeServerAction(async () => {
@@ -30,7 +33,20 @@ export async function updateAccountUserByIdAction(
30
33
  }
31
34
 
32
35
  export async function updateAccountAction(data: UpdateAccountRequest) {
33
- return safeServerAction(() => accountService.updateAccount(data));
36
+ return safeServerAction(async () => {
37
+ if (data.name !== undefined) {
38
+ const userResult = await findUserById();
39
+ if (!userResult.success || userResult.data?.profile !== UserProfile.owner) {
40
+ throw new ApiError(
41
+ 'Apenas o proprietário da conta pode alterar o nome da empresa',
42
+ 'FORBIDDEN',
43
+ 403
44
+ );
45
+ }
46
+ }
47
+
48
+ return accountService.updateAccount(data);
49
+ });
34
50
  }
35
51
 
36
52
  export async function deleteAccountUserAction(userId: number) {