fix: fix credential 3rd error
This commit is contained in:
@@ -65,6 +65,7 @@
|
||||
"input-otp": "^1.4.2",
|
||||
"jotai": "^2.12.3",
|
||||
"jotai-signal": "^0.9.0",
|
||||
"lodash-es": "^4.17.21",
|
||||
"lucide-react": "^0.512.0",
|
||||
"oidc-client-rx": "0.1.0-alpha.9",
|
||||
"react": "^19.1.0",
|
||||
@@ -91,6 +92,7 @@
|
||||
"@tanstack/react-router": "^1.112.0",
|
||||
"@tanstack/router-devtools": "^1.112.6",
|
||||
"@tanstack/router-plugin": "^1.112.13",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/react": "^19.1.2",
|
||||
"@types/react-dom": "^19.1.2",
|
||||
"chalk": "^5.4.1",
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
type SubscriptionsInsertInput,
|
||||
} from '@/infra/graphql/gql/graphql';
|
||||
import { Injectable, inject } from '@outposts/injection-js';
|
||||
import { omit } from 'lodash-es';
|
||||
import { buildMikanSubscriptionSeasonSourceUrl } from '../schema/mikan';
|
||||
import type { SubscriptionInsertForm } from '../schema/subscriptions';
|
||||
import { MikanService } from './mikan.service';
|
||||
@@ -14,18 +15,15 @@ export class SubscriptionService {
|
||||
transformInsertFormToInput(
|
||||
form: SubscriptionInsertForm
|
||||
): SubscriptionsInsertInput {
|
||||
let sourceUrl: string;
|
||||
if (form.category === SubscriptionCategoryEnum.MikanSeason) {
|
||||
sourceUrl = buildMikanSubscriptionSeasonSourceUrl(
|
||||
this.mikan.mikanBaseUrl,
|
||||
form
|
||||
).toString();
|
||||
} else {
|
||||
sourceUrl = form.sourceUrl;
|
||||
return {
|
||||
...omit(form, ['seasonStr', 'year']),
|
||||
sourceUrl: buildMikanSubscriptionSeasonSourceUrl(
|
||||
this.mikan.mikanBaseUrl,
|
||||
form
|
||||
).toString(),
|
||||
};
|
||||
}
|
||||
return {
|
||||
...form,
|
||||
sourceUrl,
|
||||
};
|
||||
return form;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,23 @@ export function arkValidatorToTypeNarrower<
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
export function validateOr<T, D>(
|
||||
validated: T | ArkErrors,
|
||||
defaultValue: D
|
||||
): T | D {
|
||||
if (validated instanceof ArkErrors) {
|
||||
return defaultValue;
|
||||
}
|
||||
return validated;
|
||||
}
|
||||
|
||||
export function validateOrElse<T, D>(
|
||||
validated: T | ArkErrors,
|
||||
elseFn: (errors: ArkErrors) => D
|
||||
): T | D {
|
||||
if (validated instanceof ArkErrors) {
|
||||
return elseFn(validated);
|
||||
}
|
||||
return validated;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { type } from 'arktype';
|
||||
import {
|
||||
BookOpen,
|
||||
Folders,
|
||||
@@ -112,3 +113,15 @@ export const AppNavMainData = [
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const CreateCompleteAction = {
|
||||
Back: 'back',
|
||||
Detail: 'detail',
|
||||
} as const;
|
||||
|
||||
export type CreateCompleteAction =
|
||||
(typeof CreateCompleteAction)[keyof typeof CreateCompleteAction];
|
||||
|
||||
export const CreateCompleteActionSchema = type.enumerated(
|
||||
...Object.values(CreateCompleteAction)
|
||||
);
|
||||
|
||||
@@ -29,33 +29,65 @@ import {
|
||||
type InsertCredential3rdMutationVariables,
|
||||
} from '@/infra/graphql/gql/graphql';
|
||||
import { PlatformService } from '@/infra/platform/platform.service';
|
||||
import {
|
||||
CreateCompleteAction,
|
||||
CreateCompleteActionSchema,
|
||||
} from '@/infra/routes/nav';
|
||||
import type { RouteStateDataOption } from '@/infra/routes/traits';
|
||||
import { useMutation } from '@apollo/client';
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router';
|
||||
import {
|
||||
createFileRoute,
|
||||
useCanGoBack,
|
||||
useNavigate,
|
||||
useRouter,
|
||||
} from '@tanstack/react-router';
|
||||
import { type } from 'arktype';
|
||||
import { Loader2, Save } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
const RouteSearchSchema = type({
|
||||
completeAction: CreateCompleteActionSchema.optional(),
|
||||
});
|
||||
|
||||
export const Route = createFileRoute('/_app/credential3rd/create')({
|
||||
component: CredentialCreateRouteComponent,
|
||||
staticData: {
|
||||
breadcrumb: { label: 'Create' },
|
||||
} satisfies RouteStateDataOption,
|
||||
validateSearch: RouteSearchSchema,
|
||||
});
|
||||
|
||||
function CredentialCreateRouteComponent() {
|
||||
const navigate = useNavigate();
|
||||
const router = useRouter();
|
||||
const canGoBack = useCanGoBack();
|
||||
const search = Route.useSearch();
|
||||
const platformService = useInject(PlatformService);
|
||||
|
||||
const handleBack = () => {
|
||||
if (canGoBack) {
|
||||
router.history.back();
|
||||
} else {
|
||||
navigate({
|
||||
to: '/credential3rd/manage',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const [insertCredential3rd, { loading }] = useMutation<
|
||||
InsertCredential3rdMutation['credential3rdCreateOne'],
|
||||
InsertCredential3rdMutation,
|
||||
InsertCredential3rdMutationVariables
|
||||
>(INSERT_CREDENTIAL_3RD, {
|
||||
onCompleted(data) {
|
||||
toast.success('Credential created');
|
||||
navigate({
|
||||
to: '/credential3rd/detail/$id',
|
||||
params: { id: `${data.id}` },
|
||||
});
|
||||
if (search.completeAction === CreateCompleteAction.Back) {
|
||||
handleBack();
|
||||
} else {
|
||||
navigate({
|
||||
to: '/credential3rd/detail/$id',
|
||||
params: { id: `${data.credential3rdCreateOne.id}` },
|
||||
});
|
||||
}
|
||||
},
|
||||
onError(error) {
|
||||
toast.error('Failed to create credential', {
|
||||
@@ -168,8 +200,6 @@ function CredentialCreateRouteComponent() {
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
|
||||
{/* 密码 */}
|
||||
<form.Field name="password">
|
||||
{(field) => (
|
||||
<div className="space-y-2">
|
||||
@@ -194,8 +224,6 @@ function CredentialCreateRouteComponent() {
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
|
||||
{/* User Agent */}
|
||||
<form.Field name="userAgent">
|
||||
{(field) => (
|
||||
<div className="space-y-2">
|
||||
|
||||
@@ -16,7 +16,12 @@ import { GET_CREDENTIAL_3RD_DETAIL } from '@/domains/recorder/schema/credential3
|
||||
import type { GetCredential3rdDetailQuery } from '@/infra/graphql/gql/graphql';
|
||||
import type { RouteStateDataOption } from '@/infra/routes/traits';
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router';
|
||||
import {
|
||||
createFileRoute,
|
||||
useCanGoBack,
|
||||
useNavigate,
|
||||
useRouter,
|
||||
} from '@tanstack/react-router';
|
||||
import { format } from 'date-fns/format';
|
||||
import { ArrowLeft, Edit, Eye, EyeOff } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
@@ -31,8 +36,21 @@ export const Route = createFileRoute('/_app/credential3rd/detail/$id')({
|
||||
function Credential3rdDetailRouteComponent() {
|
||||
const { id } = Route.useParams();
|
||||
const navigate = useNavigate();
|
||||
const router = useRouter();
|
||||
const canGoBack = useCanGoBack();
|
||||
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
|
||||
const handleBack = () => {
|
||||
if (canGoBack) {
|
||||
router.history.back();
|
||||
} else {
|
||||
navigate({
|
||||
to: '/credential3rd/manage',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const { loading, error, data } = useQuery<GetCredential3rdDetailQuery>(
|
||||
GET_CREDENTIAL_3RD_DETAIL,
|
||||
{
|
||||
@@ -43,12 +61,6 @@ function Credential3rdDetailRouteComponent() {
|
||||
}
|
||||
);
|
||||
|
||||
const handleBack = () => {
|
||||
navigate({
|
||||
to: '/credential3rd/manage',
|
||||
});
|
||||
};
|
||||
|
||||
const handleEnterEditMode = () => {
|
||||
navigate({
|
||||
to: '/credential3rd/edit/$id',
|
||||
|
||||
@@ -67,7 +67,7 @@ function FormView({
|
||||
};
|
||||
|
||||
const [updateCredential, { loading: updating }] = useMutation<
|
||||
UpdateCredential3rdMutation['credential3rdUpdate'],
|
||||
UpdateCredential3rdMutation,
|
||||
UpdateCredential3rdMutationVariables
|
||||
>(UPDATE_CREDENTIAL_3RD, {
|
||||
onCompleted,
|
||||
|
||||
@@ -7,8 +7,10 @@ import {
|
||||
type GetCredential3rdQueryVariables,
|
||||
OrderByEnum,
|
||||
} from '@/infra/graphql/gql/graphql';
|
||||
import { CreateCompleteAction } from '@/infra/routes/nav';
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { AlertCircle, Loader2, RefreshCw } from 'lucide-react';
|
||||
import { useNavigate } from '@tanstack/react-router';
|
||||
import { AlertCircle, Loader2, Plus, RefreshCw } from 'lucide-react';
|
||||
import type { ComponentProps } from 'react';
|
||||
|
||||
export interface Credential3rdSelectContentProps
|
||||
@@ -20,6 +22,8 @@ export function Credential3rdSelectContent({
|
||||
credentialType,
|
||||
...props
|
||||
}: Credential3rdSelectContentProps) {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { data, loading, error, refetch } = useQuery<
|
||||
GetCredential3rdQuery,
|
||||
GetCredential3rdQueryVariables
|
||||
@@ -76,10 +80,24 @@ export function Credential3rdSelectContent({
|
||||
{!loading &&
|
||||
!error &&
|
||||
(credentials.length === 0 ? (
|
||||
<div className="py-6 text-center">
|
||||
<div className="flex flex-col items-center gap-2 py-6 text-center">
|
||||
<span className="text-muted-foreground text-sm">
|
||||
No credentials found
|
||||
</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
navigate({
|
||||
to: '/credential3rd/create',
|
||||
search: {
|
||||
completeAction: CreateCompleteAction.Back,
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
<Plus className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
credentials.map((credential) => (
|
||||
|
||||
@@ -52,14 +52,14 @@ function SubscriptionCreateRouteComponent() {
|
||||
const subscriptionService = useInject(SubscriptionService);
|
||||
|
||||
const [insertSubscription, { loading }] = useMutation<
|
||||
InsertSubscriptionMutation['subscriptionsCreateOne'],
|
||||
InsertSubscriptionMutation,
|
||||
InsertSubscriptionMutationVariables
|
||||
>(INSERT_SUBSCRIPTION, {
|
||||
onCompleted(data) {
|
||||
toast.success('Subscription created');
|
||||
navigate({
|
||||
to: '/subscriptions/detail/$id',
|
||||
params: { id: `${data.id}` },
|
||||
params: { id: `${data.subscriptionsCreateOne.id}` },
|
||||
});
|
||||
},
|
||||
onError(error) {
|
||||
@@ -80,7 +80,8 @@ function SubscriptionCreateRouteComponent() {
|
||||
seasonStr: '',
|
||||
} as unknown as SubscriptionInsertForm,
|
||||
validators: {
|
||||
onBlur: SubscriptionInsertFormSchema,
|
||||
onChangeAsync: SubscriptionInsertFormSchema,
|
||||
onChangeAsyncDebounceMs: 300,
|
||||
onSubmit: SubscriptionInsertFormSchema,
|
||||
},
|
||||
onSubmit: async (form) => {
|
||||
@@ -233,7 +234,7 @@ function SubscriptionCreateRouteComponent() {
|
||||
Number.parseInt(e.target.value)
|
||||
)
|
||||
}
|
||||
placeholder="Please enter full year (e.g. 2025)"
|
||||
placeholder={`Please enter full year (e.g. ${new Date().getFullYear()})`}
|
||||
autoComplete="off"
|
||||
/>
|
||||
{field.state.meta.errors && (
|
||||
@@ -252,7 +253,12 @@ function SubscriptionCreateRouteComponent() {
|
||||
{(field) => (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={field.name}>Season *</Label>
|
||||
<Select>
|
||||
<Select
|
||||
value={field.state.value}
|
||||
onValueChange={(value) =>
|
||||
field.handleChange(value as MikanSeasonEnum)
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select season" />
|
||||
</SelectTrigger>
|
||||
|
||||
Reference in New Issue
Block a user