Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lelemm committed Oct 3, 2024
1 parent 2c13abc commit 5a23f3f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ type UserAccessProps = {
export const UserAccessRow = memo(
({ access, hovered, onHover }: UserAccessProps) => {
const backgroundFocus = hovered;
const [marked, setMarked] = useState(access.owner === 1 || access.haveAccess === 1);
const [marked, setMarked] = useState(
access.owner === 1 || access.haveAccess === 1,
);
const [cloudFileId] = useMetadataPref('cloudFileId');
const actions = useActions();

Expand Down
37 changes: 21 additions & 16 deletions packages/desktop-client/src/components/modals/EditUser.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useState } from 'react';

import { send } from 'loot-core/platform/client/fetch';
import { PossibleRoles, UserEntity } from 'loot-core/src/types/models/user';
import {
PossibleRoles,
type UserEntity,
} from 'loot-core/src/types/models/user';

import { useActions } from '../../hooks/useActions';
import { type BoundActions, useActions } from '../../hooks/useActions';
import { styles, theme } from '../../style';
import { Button } from '../common/Button2';
import { Input } from '../common/Input';
Expand All @@ -14,20 +17,22 @@ import { Text } from '../common/Text';
import { View } from '../common/View';
import { Checkbox, FormField, FormLabel } from '../forms';

interface EditUserProps {
defaultUser: UserEntity;
type User = UserEntity;

type EditUserProps = {
defaultUser: User;
onSave: (
method: 'user-add' | 'user-update',
user: UserEntity,
user: User,
setError: (error: string) => void,
actions: any,
actions: BoundActions,
) => Promise<void>;
}
};

interface EditUserFinanceAppProps {
defaultUser: UserEntity;
onSave: (user: UserEntity) => void;
}
type EditUserFinanceAppProps = {
defaultUser: User;
onSave: (user: User) => void;
};

function getUserDirectoryErrors(reason: string): string {
switch (reason) {
Expand All @@ -52,9 +57,9 @@ function getUserDirectoryErrors(reason: string): string {

async function saveUser(
method: 'user-add' | 'user-update',
user: UserEntity,
user: User,
setError: (error: string) => void,
actions: any,
actions: BoundActions,
): Promise<boolean> {
const { error, id: newId } = (await send(method, user)) || {};
if (!error) {
Expand Down Expand Up @@ -120,12 +125,12 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) {
);
const [enabled, setEnabled] = useState<boolean>(defaultUser.enabled);
const [role, setRole] = useState<string>(
defaultUser.role ?? PossibleRoles.Admin,
defaultUser.role ?? '213733c1-5645-46ad-8784-a7b20b400f93',
);
const [error, setError] = useState<string>('');

async function onSave() {
const user: UserEntity = {
const user: User = {
...defaultUser,
userName,
displayName,
Expand Down Expand Up @@ -250,7 +255,7 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) {
);
}

const RoleDescription: React.FC = () => {
const RoleDescription = () => {
return (
<View style={{ paddingTop: 10 }}>
<Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ export function PasswordEnableModal({
'invalid-password': 'Invalid Password',
'password-match': 'Passwords do not match',
'network-failure': 'Unable to contact the server',
'unable-to-change-file-config-enabled': 'Unable to disable OpenID. Please update the config.json file in this case.',
'unable-to-change-file-config-enabled':
'Unable to disable OpenID. Please update the config.json file in this case.',
};

function getErrorMessage(error: string): string {
return errorMessages[error as keyof typeof errorMessages] || 'Internal server error';
return (
errorMessages[error as keyof typeof errorMessages] ||
'Internal server error'
);
}

async function onSetPassword(password: string) {
Expand Down
10 changes: 4 additions & 6 deletions packages/loot-core/src/types/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface NewUserEntity {
userName: string;
displayName: string;
role: UserRole;
role: string;
enabled: boolean;
}

Expand All @@ -24,9 +24,7 @@ export interface UserAvailable {
owner?: number;
}

export type UserRole = 'Admin' | 'Basic';

export const PossibleRoles: Record<UserRole, string> = {
Admin: '213733c1-5645-46ad-8784-a7b20b400f93',
Basic: 'e87fa1f1-ac8c-4913-b1b5-1096bdb1eacc',
export const PossibleRoles = {
'213733c1-5645-46ad-8784-a7b20b400f93': 'Admin',
'e87fa1f1-ac8c-4913-b1b5-1096bdb1eacc': 'Basic',
};

0 comments on commit 5a23f3f

Please sign in to comment.