Skip to content

Commit

Permalink
fix: Conflict errors in front
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-dalmet committed Oct 2, 2023
1 parent dcd586a commit 09efc23
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/features/account/PageProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
DEFAULT_LANGUAGE_KEY,
} from '@/lib/i18n/constants';
import { trpc } from '@/lib/trpc/client';
import { isErrorDatabaseConflict } from '@/lib/trpc/errors';

export default function PageProfile() {
const { t } = useTranslation(['common', 'account']);
Expand All @@ -37,7 +38,7 @@ export default function PageProfile() {
});
},
onError: (error) => {
if (error.data?.code === 'CONFLICT') {
if (isErrorDatabaseConflict(error, 'email')) {
profileForm.setErrors({
email: t('account:data.email.alreadyUsed'),
});
Expand Down
3 changes: 2 additions & 1 deletion src/features/auth/PageRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useToastError } from '@/components/Toast';
import { DemoRegisterHint } from '@/features/demo-mode/DemoRegisterHint';
import { AVAILABLE_LANGUAGES, Language } from '@/lib/i18n/constants';
import { trpc } from '@/lib/trpc/client';
import { isErrorDatabaseConflict } from '@/lib/trpc/errors';

export default function PageRegister() {
const { t, i18n } = useTranslation(['common', 'auth']);
Expand All @@ -38,7 +39,7 @@ export default function PageRegister() {
setAccountEmail(email);
},
onError: (error) => {
if (error.data?.code === 'CONFLICT') {
if (isErrorDatabaseConflict(error, 'email')) {
form.setErrors({ email: t('auth:data.email.alreadyUsed') });
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/features/repositories/PageRepositoryCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
RepositoryFormFields,
} from '@/features/repositories/RepositoryForm';
import { trpc } from '@/lib/trpc/client';
import { isErrorDatabaseConflict } from '@/lib/trpc/errors';

export default function PageRepositoryCreate() {
const { t } = useTranslation(['common', 'repositories']);
Expand All @@ -35,7 +36,7 @@ export default function PageRepositoryCreate() {
router.back();
},
onError: (error) => {
if (error.data?.code === 'CONFLICT') {
if (isErrorDatabaseConflict(error, 'email')) {
form.setErrors({ email: t('repositories:data.name.alreadyUsed') });
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/features/repositories/PageRepositoryUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '@/features/repositories/RepositoryForm';
import { Loader } from '@/layout/Loader';
import { trpc } from '@/lib/trpc/client';
import { isErrorDatabaseConflict } from '@/lib/trpc/errors';

export default function PageRepositoryUpdate() {
const { t } = useTranslation(['common', 'repositories']);
Expand Down Expand Up @@ -56,7 +57,7 @@ export default function PageRepositoryUpdate() {
router.back();
},
onError: (error) => {
if (error.data?.code === 'CONFLICT') {
if (isErrorDatabaseConflict(error, 'email')) {
form.setErrors({ email: t('repositories:data.name.alreadyUsed') });
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/features/users/PageUserUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { UserForm, UserFormFields } from '@/features/users/UserForm';
import { UserStatus } from '@/features/users/UserStatus';
import { Loader } from '@/layout/Loader';
import { trpc } from '@/lib/trpc/client';
import { isErrorDatabaseConflict } from '@/lib/trpc/errors';

export default function PageUserUpdate() {
const { t } = useTranslation(['common', 'users']);
Expand Down Expand Up @@ -55,7 +56,7 @@ export default function PageUserUpdate() {
router.back();
},
onError: (error) => {
if (error.data?.code === 'CONFLICT') {
if (isErrorDatabaseConflict(error, 'email')) {
form.setErrors({ email: t('users:data.email.alreadyUsed') });
return;
}
Expand Down

0 comments on commit 09efc23

Please sign in to comment.