Compare commits
2 Commits
c669d66969
...
946d4e8c2c
Author | SHA1 | Date | |
---|---|---|---|
946d4e8c2c | |||
0b5f25a263 |
36
Cargo.lock
generated
36
Cargo.lock
generated
@ -886,9 +886,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.23.0"
|
||||
version = "1.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9134a6ef01ce4b366b50689c94f82c14bc72bc5d0386829828a2e2752ef7958c"
|
||||
checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
@ -2347,11 +2347,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "getopts"
|
||||
version = "0.2.21"
|
||||
version = "0.2.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
|
||||
checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
"unicode-width 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2523,9 +2523,9 @@ checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.3"
|
||||
version = "0.15.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3"
|
||||
checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
|
||||
dependencies = [
|
||||
"allocator-api2",
|
||||
"equivalent",
|
||||
@ -2538,7 +2538,7 @@ version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1"
|
||||
dependencies = [
|
||||
"hashbrown 0.15.3",
|
||||
"hashbrown 0.15.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3027,7 +3027,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.15.3",
|
||||
"hashbrown 0.15.4",
|
||||
"serde",
|
||||
]
|
||||
|
||||
@ -3091,7 +3091,7 @@ dependencies = [
|
||||
"newline-converter",
|
||||
"once_cell",
|
||||
"unicode-segmentation",
|
||||
"unicode-width",
|
||||
"unicode-width 0.1.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3751,7 +3751,7 @@ version = "0.12.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38"
|
||||
dependencies = [
|
||||
"hashbrown 0.15.3",
|
||||
"hashbrown 0.15.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3871,7 +3871,7 @@ dependencies = [
|
||||
"miette-derive",
|
||||
"once_cell",
|
||||
"thiserror 1.0.69",
|
||||
"unicode-width",
|
||||
"unicode-width 0.1.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -6513,7 +6513,7 @@ dependencies = [
|
||||
"futures-intrusive",
|
||||
"futures-io",
|
||||
"futures-util",
|
||||
"hashbrown 0.15.3",
|
||||
"hashbrown 0.15.4",
|
||||
"hashlink",
|
||||
"indexmap 2.9.0",
|
||||
"log",
|
||||
@ -7623,6 +7623,12 @@ version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||
|
||||
[[package]]
|
||||
name = "universal-hash"
|
||||
version = "0.5.1"
|
||||
@ -8492,9 +8498,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zune-jpeg"
|
||||
version = "0.4.16"
|
||||
version = "0.4.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e4a518c0ea2576f4da876349d7f67a7be489297cd77c2cf9e04c2e05fcd3974"
|
||||
checksum = "0f6fe2e33d02a98ee64423802e16df3de99c43e5cf5ff983767e1128b394c8ac"
|
||||
dependencies = [
|
||||
"zune-core",
|
||||
]
|
||||
|
@ -28,7 +28,11 @@ impl MigrationTrait for Migration {
|
||||
table_auto_z(Credential3rd::Table)
|
||||
.col(pk_auto(Credential3rd::Id))
|
||||
.col(integer(Credential3rd::SubscriberId))
|
||||
.col(string(Credential3rd::CredentialType))
|
||||
.col(enumeration(
|
||||
Credential3rd::CredentialType,
|
||||
Credential3rdTypeEnum,
|
||||
Credential3rdType::iden_values(),
|
||||
))
|
||||
.col(string_null(Credential3rd::Cookies))
|
||||
.col(string_null(Credential3rd::Username))
|
||||
.col(string_null(Credential3rd::Password))
|
||||
|
@ -18,6 +18,7 @@ use crate::{
|
||||
db_type = "Enum",
|
||||
enum_name = "credential_3rd_type"
|
||||
)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Credential3rdType {
|
||||
#[sea_orm(string_value = "mikan")]
|
||||
Mikan,
|
||||
|
@ -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",
|
||||
|
@ -179,14 +179,3 @@ export function extractMikanSubscriptionSubscriberSourceUrl(
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function extractMikanSubscriptionSourceUrl(
|
||||
sourceUrl: string
|
||||
): MikanSubscriptionSourceUrl | ArkErrors {
|
||||
const u = new URL(sourceUrl);
|
||||
return MikanSubscriptionSourceUrlSchema({
|
||||
category: SubscriptionCategoryEnum.MikanBangumi,
|
||||
mikanBangumiId: u.searchParams.get(MIKAN_BANGUMI_ID_QUERY_KEY),
|
||||
mikanFansubId: u.searchParams.get(MIKAN_FANSUB_ID_QUERY_KEY),
|
||||
});
|
||||
}
|
||||
|
@ -96,6 +96,7 @@ query GetSubscriptionDetail ($id: Int!) {
|
||||
enabled
|
||||
credential3rd {
|
||||
id
|
||||
username
|
||||
}
|
||||
bangumi {
|
||||
nodes {
|
||||
|
@ -3,7 +3,17 @@ import {
|
||||
type SubscriptionsInsertInput,
|
||||
} from '@/infra/graphql/gql/graphql';
|
||||
import { Injectable, inject } from '@outposts/injection-js';
|
||||
import { buildMikanSubscriptionSeasonSourceUrl } from '../schema/mikan';
|
||||
import { ArkErrors } from 'arktype';
|
||||
import { omit } from 'lodash-es';
|
||||
import {
|
||||
type MikanSubscriptionBangumiSourceUrl,
|
||||
type MikanSubscriptionSeasonSourceUrl,
|
||||
type MikanSubscriptionSubscriberSourceUrl,
|
||||
buildMikanSubscriptionSeasonSourceUrl,
|
||||
extractMikanSubscriptionBangumiSourceUrl,
|
||||
extractMikanSubscriptionSeasonSourceUrl,
|
||||
extractMikanSubscriptionSubscriberSourceUrl,
|
||||
} from '../schema/mikan';
|
||||
import type { SubscriptionInsertForm } from '../schema/subscriptions';
|
||||
import { MikanService } from './mikan.service';
|
||||
|
||||
@ -14,18 +24,39 @@ 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;
|
||||
}
|
||||
|
||||
extractSourceUrlMeta(
|
||||
category: SubscriptionCategoryEnum,
|
||||
sourceUrl: string
|
||||
):
|
||||
| MikanSubscriptionSeasonSourceUrl
|
||||
| MikanSubscriptionBangumiSourceUrl
|
||||
| MikanSubscriptionSubscriberSourceUrl
|
||||
| null {
|
||||
let meta:
|
||||
| MikanSubscriptionSeasonSourceUrl
|
||||
| MikanSubscriptionBangumiSourceUrl
|
||||
| MikanSubscriptionSubscriberSourceUrl
|
||||
| null
|
||||
| ArkErrors = null;
|
||||
if (category === SubscriptionCategoryEnum.MikanSeason) {
|
||||
meta = extractMikanSubscriptionSeasonSourceUrl(sourceUrl);
|
||||
} else if (category === SubscriptionCategoryEnum.MikanBangumi) {
|
||||
meta = extractMikanSubscriptionBangumiSourceUrl(sourceUrl);
|
||||
} else if (category === SubscriptionCategoryEnum.MikanSubscriber) {
|
||||
meta = extractMikanSubscriptionSubscriberSourceUrl(sourceUrl);
|
||||
}
|
||||
return meta instanceof ArkErrors ? null : meta;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ type Documents = {
|
||||
"\n mutation InsertSubscription($data: SubscriptionsInsertInput!) {\n subscriptionsCreateOne(data: $data) {\n id\n createdAt\n updatedAt\n displayName\n category\n sourceUrl\n enabled\n credentialId\n }\n }\n": typeof types.InsertSubscriptionDocument,
|
||||
"\n mutation UpdateSubscriptions(\n $data: SubscriptionsUpdateInput!,\n $filters: SubscriptionsFilterInput!,\n ) {\n subscriptionsUpdate (\n data: $data\n filter: $filters\n ) {\n id\n createdAt\n updatedAt\n displayName\n category\n sourceUrl\n enabled\n }\n}\n": typeof types.UpdateSubscriptionsDocument,
|
||||
"\n mutation DeleteSubscriptions($filters: SubscriptionsFilterInput) {\n subscriptionsDelete(filter: $filters)\n }\n": typeof types.DeleteSubscriptionsDocument,
|
||||
"\nquery GetSubscriptionDetail ($id: Int!) {\n subscriptions(filters: { id: {\n eq: $id\n } }) {\n nodes {\n id\n displayName\n createdAt\n updatedAt\n category\n sourceUrl\n enabled\n credential3rd {\n id\n }\n bangumi {\n nodes {\n createdAt\n updatedAt\n id\n mikanBangumiId\n displayName\n rawName\n season\n seasonRaw\n fansub\n mikanFansubId\n rssLink\n posterLink\n savePath\n homepage\n }\n }\n }\n }\n}\n": typeof types.GetSubscriptionDetailDocument,
|
||||
"\nquery GetSubscriptionDetail ($id: Int!) {\n subscriptions(filters: { id: {\n eq: $id\n } }) {\n nodes {\n id\n displayName\n createdAt\n updatedAt\n category\n sourceUrl\n enabled\n credential3rd {\n id\n username\n }\n bangumi {\n nodes {\n createdAt\n updatedAt\n id\n mikanBangumiId\n displayName\n rawName\n season\n seasonRaw\n fansub\n mikanFansubId\n rssLink\n posterLink\n savePath\n homepage\n }\n }\n }\n }\n}\n": typeof types.GetSubscriptionDetailDocument,
|
||||
};
|
||||
const documents: Documents = {
|
||||
"\n query GetCredential3rd($filters: Credential3rdFilterInput!, $orderBy: Credential3rdOrderInput, $pagination: PaginationInput) {\n credential3rd(filters: $filters, orderBy: $orderBy, pagination: $pagination) {\n nodes {\n id\n cookies\n username\n password\n userAgent\n createdAt\n updatedAt\n credentialType\n }\n paginationInfo {\n total\n pages\n }\n }\n }\n": types.GetCredential3rdDocument,
|
||||
@ -35,7 +35,7 @@ const documents: Documents = {
|
||||
"\n mutation InsertSubscription($data: SubscriptionsInsertInput!) {\n subscriptionsCreateOne(data: $data) {\n id\n createdAt\n updatedAt\n displayName\n category\n sourceUrl\n enabled\n credentialId\n }\n }\n": types.InsertSubscriptionDocument,
|
||||
"\n mutation UpdateSubscriptions(\n $data: SubscriptionsUpdateInput!,\n $filters: SubscriptionsFilterInput!,\n ) {\n subscriptionsUpdate (\n data: $data\n filter: $filters\n ) {\n id\n createdAt\n updatedAt\n displayName\n category\n sourceUrl\n enabled\n }\n}\n": types.UpdateSubscriptionsDocument,
|
||||
"\n mutation DeleteSubscriptions($filters: SubscriptionsFilterInput) {\n subscriptionsDelete(filter: $filters)\n }\n": types.DeleteSubscriptionsDocument,
|
||||
"\nquery GetSubscriptionDetail ($id: Int!) {\n subscriptions(filters: { id: {\n eq: $id\n } }) {\n nodes {\n id\n displayName\n createdAt\n updatedAt\n category\n sourceUrl\n enabled\n credential3rd {\n id\n }\n bangumi {\n nodes {\n createdAt\n updatedAt\n id\n mikanBangumiId\n displayName\n rawName\n season\n seasonRaw\n fansub\n mikanFansubId\n rssLink\n posterLink\n savePath\n homepage\n }\n }\n }\n }\n}\n": types.GetSubscriptionDetailDocument,
|
||||
"\nquery GetSubscriptionDetail ($id: Int!) {\n subscriptions(filters: { id: {\n eq: $id\n } }) {\n nodes {\n id\n displayName\n createdAt\n updatedAt\n category\n sourceUrl\n enabled\n credential3rd {\n id\n username\n }\n bangumi {\n nodes {\n createdAt\n updatedAt\n id\n mikanBangumiId\n displayName\n rawName\n season\n seasonRaw\n fansub\n mikanFansubId\n rssLink\n posterLink\n savePath\n homepage\n }\n }\n }\n }\n}\n": types.GetSubscriptionDetailDocument,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -91,7 +91,7 @@ export function gql(source: "\n mutation DeleteSubscriptions($filters: Subscr
|
||||
/**
|
||||
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function gql(source: "\nquery GetSubscriptionDetail ($id: Int!) {\n subscriptions(filters: { id: {\n eq: $id\n } }) {\n nodes {\n id\n displayName\n createdAt\n updatedAt\n category\n sourceUrl\n enabled\n credential3rd {\n id\n }\n bangumi {\n nodes {\n createdAt\n updatedAt\n id\n mikanBangumiId\n displayName\n rawName\n season\n seasonRaw\n fansub\n mikanFansubId\n rssLink\n posterLink\n savePath\n homepage\n }\n }\n }\n }\n}\n"): (typeof documents)["\nquery GetSubscriptionDetail ($id: Int!) {\n subscriptions(filters: { id: {\n eq: $id\n } }) {\n nodes {\n id\n displayName\n createdAt\n updatedAt\n category\n sourceUrl\n enabled\n credential3rd {\n id\n }\n bangumi {\n nodes {\n createdAt\n updatedAt\n id\n mikanBangumiId\n displayName\n rawName\n season\n seasonRaw\n fansub\n mikanFansubId\n rssLink\n posterLink\n savePath\n homepage\n }\n }\n }\n }\n}\n"];
|
||||
export function gql(source: "\nquery GetSubscriptionDetail ($id: Int!) {\n subscriptions(filters: { id: {\n eq: $id\n } }) {\n nodes {\n id\n displayName\n createdAt\n updatedAt\n category\n sourceUrl\n enabled\n credential3rd {\n id\n username\n }\n bangumi {\n nodes {\n createdAt\n updatedAt\n id\n mikanBangumiId\n displayName\n rawName\n season\n seasonRaw\n fansub\n mikanFansubId\n rssLink\n posterLink\n savePath\n homepage\n }\n }\n }\n }\n}\n"): (typeof documents)["\nquery GetSubscriptionDetail ($id: Int!) {\n subscriptions(filters: { id: {\n eq: $id\n } }) {\n nodes {\n id\n displayName\n createdAt\n updatedAt\n category\n sourceUrl\n enabled\n credential3rd {\n id\n username\n }\n bangumi {\n nodes {\n createdAt\n updatedAt\n id\n mikanBangumiId\n displayName\n rawName\n season\n seasonRaw\n fansub\n mikanFansubId\n rssLink\n posterLink\n savePath\n homepage\n }\n }\n }\n }\n}\n"];
|
||||
|
||||
export function gql(source: string) {
|
||||
return (documents as any)[source] ?? {};
|
||||
|
@ -1714,7 +1714,7 @@ export type GetSubscriptionDetailQueryVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type GetSubscriptionDetailQuery = { __typename?: 'Query', subscriptions: { __typename?: 'SubscriptionsConnection', nodes: Array<{ __typename?: 'Subscriptions', id: number, displayName: string, createdAt: string, updatedAt: string, category: SubscriptionCategoryEnum, sourceUrl: string, enabled: boolean, credential3rd?: { __typename?: 'Credential3rd', id: number } | null, bangumi: { __typename?: 'BangumiConnection', nodes: Array<{ __typename?: 'Bangumi', createdAt: string, updatedAt: string, id: number, mikanBangumiId?: string | null, displayName: string, rawName: string, season: number, seasonRaw?: string | null, fansub?: string | null, mikanFansubId?: string | null, rssLink?: string | null, posterLink?: string | null, savePath?: string | null, homepage?: string | null }> } }> } };
|
||||
export type GetSubscriptionDetailQuery = { __typename?: 'Query', subscriptions: { __typename?: 'SubscriptionsConnection', nodes: Array<{ __typename?: 'Subscriptions', id: number, displayName: string, createdAt: string, updatedAt: string, category: SubscriptionCategoryEnum, sourceUrl: string, enabled: boolean, credential3rd?: { __typename?: 'Credential3rd', id: number, username?: string | null } | null, bangumi: { __typename?: 'BangumiConnection', nodes: Array<{ __typename?: 'Bangumi', createdAt: string, updatedAt: string, id: number, mikanBangumiId?: string | null, displayName: string, rawName: string, season: number, seasonRaw?: string | null, fansub?: string | null, mikanFansubId?: string | null, rssLink?: string | null, posterLink?: string | null, savePath?: string | null, homepage?: string | null }> } }> } };
|
||||
|
||||
|
||||
export const GetCredential3rdDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCredential3rd"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"filters"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Credential3rdFilterInput"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"orderBy"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Credential3rdOrderInput"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"pagination"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"PaginationInput"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"credential3rd"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"Variable","name":{"kind":"Name","value":"filters"}}},{"kind":"Argument","name":{"kind":"Name","value":"orderBy"},"value":{"kind":"Variable","name":{"kind":"Name","value":"orderBy"}}},{"kind":"Argument","name":{"kind":"Name","value":"pagination"},"value":{"kind":"Variable","name":{"kind":"Name","value":"pagination"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"cookies"}},{"kind":"Field","name":{"kind":"Name","value":"username"}},{"kind":"Field","name":{"kind":"Name","value":"password"}},{"kind":"Field","name":{"kind":"Name","value":"userAgent"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"credentialType"}}]}},{"kind":"Field","name":{"kind":"Name","value":"paginationInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"total"}},{"kind":"Field","name":{"kind":"Name","value":"pages"}}]}}]}}]}}]} as unknown as DocumentNode<GetCredential3rdQuery, GetCredential3rdQueryVariables>;
|
||||
@ -1726,4 +1726,4 @@ export const GetSubscriptionsDocument = {"kind":"Document","definitions":[{"kind
|
||||
export const InsertSubscriptionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"InsertSubscription"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"data"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SubscriptionsInsertInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"subscriptionsCreateOne"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"data"},"value":{"kind":"Variable","name":{"kind":"Name","value":"data"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"category"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrl"}},{"kind":"Field","name":{"kind":"Name","value":"enabled"}},{"kind":"Field","name":{"kind":"Name","value":"credentialId"}}]}}]}}]} as unknown as DocumentNode<InsertSubscriptionMutation, InsertSubscriptionMutationVariables>;
|
||||
export const UpdateSubscriptionsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateSubscriptions"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"data"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SubscriptionsUpdateInput"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"filters"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SubscriptionsFilterInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"subscriptionsUpdate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"data"},"value":{"kind":"Variable","name":{"kind":"Name","value":"data"}}},{"kind":"Argument","name":{"kind":"Name","value":"filter"},"value":{"kind":"Variable","name":{"kind":"Name","value":"filters"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"category"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrl"}},{"kind":"Field","name":{"kind":"Name","value":"enabled"}}]}}]}}]} as unknown as DocumentNode<UpdateSubscriptionsMutation, UpdateSubscriptionsMutationVariables>;
|
||||
export const DeleteSubscriptionsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteSubscriptions"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"filters"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"SubscriptionsFilterInput"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"subscriptionsDelete"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filter"},"value":{"kind":"Variable","name":{"kind":"Name","value":"filters"}}}]}]}}]} as unknown as DocumentNode<DeleteSubscriptionsMutation, DeleteSubscriptionsMutationVariables>;
|
||||
export const GetSubscriptionDetailDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSubscriptionDetail"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"subscriptions"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"id"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"category"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrl"}},{"kind":"Field","name":{"kind":"Name","value":"enabled"}},{"kind":"Field","name":{"kind":"Name","value":"credential3rd"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"bangumi"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"mikanBangumiId"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"rawName"}},{"kind":"Field","name":{"kind":"Name","value":"season"}},{"kind":"Field","name":{"kind":"Name","value":"seasonRaw"}},{"kind":"Field","name":{"kind":"Name","value":"fansub"}},{"kind":"Field","name":{"kind":"Name","value":"mikanFansubId"}},{"kind":"Field","name":{"kind":"Name","value":"rssLink"}},{"kind":"Field","name":{"kind":"Name","value":"posterLink"}},{"kind":"Field","name":{"kind":"Name","value":"savePath"}},{"kind":"Field","name":{"kind":"Name","value":"homepage"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<GetSubscriptionDetailQuery, GetSubscriptionDetailQueryVariables>;
|
||||
export const GetSubscriptionDetailDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSubscriptionDetail"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"subscriptions"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"id"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"category"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrl"}},{"kind":"Field","name":{"kind":"Name","value":"enabled"}},{"kind":"Field","name":{"kind":"Name","value":"credential3rd"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"username"}}]}},{"kind":"Field","name":{"kind":"Name","value":"bangumi"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"mikanBangumiId"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"rawName"}},{"kind":"Field","name":{"kind":"Name","value":"season"}},{"kind":"Field","name":{"kind":"Name","value":"seasonRaw"}},{"kind":"Field","name":{"kind":"Name","value":"fansub"}},{"kind":"Field","name":{"kind":"Name","value":"mikanFansubId"}},{"kind":"Field","name":{"kind":"Name","value":"rssLink"}},{"kind":"Field","name":{"kind":"Name","value":"posterLink"}},{"kind":"Field","name":{"kind":"Name","value":"savePath"}},{"kind":"Field","name":{"kind":"Name","value":"homepage"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<GetSubscriptionDetailQuery, GetSubscriptionDetailQueryVariables>;
|
@ -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', {
|
||||
@ -72,7 +104,8 @@ function CredentialCreateRouteComponent() {
|
||||
userAgent: '',
|
||||
},
|
||||
validators: {
|
||||
onBlur: Credential3rdInsertSchema,
|
||||
onChangeAsync: Credential3rdInsertSchema,
|
||||
onChangeAsyncDebounceMs: 300,
|
||||
onSubmit: Credential3rdInsertSchema,
|
||||
},
|
||||
onSubmit: async (form) => {
|
||||
@ -168,8 +201,6 @@ function CredentialCreateRouteComponent() {
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
|
||||
{/* 密码 */}
|
||||
<form.Field name="password">
|
||||
{(field) => (
|
||||
<div className="space-y-2">
|
||||
@ -194,8 +225,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',
|
||||
@ -113,9 +125,7 @@ function Credential3rdDetailRouteComponent() {
|
||||
View credential detail
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Badge variant="secondary" className="capitalize">
|
||||
{credential.credentialType}
|
||||
</Badge>
|
||||
<Badge variant="secondary">{credential.credentialType}</Badge>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
@ -131,9 +141,7 @@ function Credential3rdDetailRouteComponent() {
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">Credential type</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<Badge variant="secondary" className="capitalize">
|
||||
{credential.credentialType}
|
||||
</Badge>
|
||||
<Badge variant="secondary">{credential.credentialType}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -1,36 +1,346 @@
|
||||
import type { GetSubscriptionDetailQuery } from '@/infra/graphql/gql/graphql';
|
||||
import { DetailCardSkeleton } from '@/components/detail-card-skeleton';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { DetailEmptyView } from '@/components/ui/detail-empty-view';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { QueryErrorView } from '@/components/ui/query-error-view';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { GET_SUBSCRIPTION_DETAIL } from '@/domains/recorder/schema/subscriptions';
|
||||
import { SubscriptionService } from '@/domains/recorder/services/subscription.service';
|
||||
import { useInject } from '@/infra/di/inject';
|
||||
import {
|
||||
type GetSubscriptionDetailQuery,
|
||||
SubscriptionCategoryEnum,
|
||||
} from '@/infra/graphql/gql/graphql';
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import { GET_SUBSCRIPTION_DETAIL } from '../../../../domains/recorder/schema/subscriptions.js';
|
||||
import {
|
||||
createFileRoute,
|
||||
useCanGoBack,
|
||||
useNavigate,
|
||||
useRouter,
|
||||
} from '@tanstack/react-router';
|
||||
import { format } from 'date-fns';
|
||||
import { ArrowLeft, Edit, ExternalLink } from 'lucide-react';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export const Route = createFileRoute('/_app/subscriptions/detail/$id')({
|
||||
component: DetailRouteComponent,
|
||||
component: SubscriptionDetailRouteComponent,
|
||||
});
|
||||
|
||||
function DetailRouteComponent() {
|
||||
function SubscriptionDetailRouteComponent() {
|
||||
const { id } = Route.useParams();
|
||||
const navigate = useNavigate();
|
||||
const router = useRouter();
|
||||
const canGoBack = useCanGoBack();
|
||||
const subscriptionService = useInject(SubscriptionService);
|
||||
|
||||
const handleBack = () => {
|
||||
if (canGoBack) {
|
||||
router.history.back();
|
||||
} else {
|
||||
navigate({
|
||||
to: '/subscriptions/manage',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const { data, loading, error } = useQuery<GetSubscriptionDetailQuery>(
|
||||
GET_SUBSCRIPTION_DETAIL,
|
||||
{
|
||||
variables: {
|
||||
id: Number.parseInt(id),
|
||||
},
|
||||
fetchPolicy: 'cache-and-network',
|
||||
}
|
||||
);
|
||||
|
||||
const handleEnterEditMode = () => {
|
||||
navigate({
|
||||
to: '/subscriptions/edit/$id',
|
||||
params: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
};
|
||||
const subscription = data?.subscriptions?.nodes?.[0];
|
||||
|
||||
const sourceUrlMeta = useMemo(
|
||||
() =>
|
||||
subscription
|
||||
? subscriptionService.extractSourceUrlMeta(
|
||||
subscription?.category,
|
||||
subscription?.sourceUrl
|
||||
)
|
||||
: null,
|
||||
[
|
||||
subscription,
|
||||
subscription?.category,
|
||||
subscription?.sourceUrl,
|
||||
subscriptionService.extractSourceUrlMeta,
|
||||
]
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
return <div>Loading...</div>;
|
||||
return <DetailCardSkeleton />;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <div>Error: {error.message}</div>;
|
||||
return <QueryErrorView message={error.message} />;
|
||||
}
|
||||
|
||||
const detail = data?.subscriptions?.nodes?.[0];
|
||||
if (!subscription) {
|
||||
return <DetailEmptyView message="Not found certain subscription" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(detail, null, 2) }}
|
||||
/>
|
||||
<div className="container mx-auto max-w-4xl py-6">
|
||||
<div className="mb-6 flex items-center justify-between">
|
||||
<div className="flex items-center gap-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleBack}
|
||||
className="h-8 w-8 p-0"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<div>
|
||||
<h1 className="font-bold text-2xl">Subscription detail</h1>
|
||||
<p className="mt-1 text-muted-foreground">
|
||||
View subscription #{subscription.id}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button onClick={handleEnterEditMode}>
|
||||
<Edit className="mr-2 h-4 w-4" />
|
||||
Edit
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<CardTitle>Subscription information</CardTitle>
|
||||
<CardDescription className="mt-2">
|
||||
View subscription detail
|
||||
</CardDescription>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Badge variant={subscription.enabled ? 'default' : 'secondary'}>
|
||||
{subscription.enabled ? 'Enabled' : 'Disabled'}
|
||||
</Badge>
|
||||
<Badge variant="outline">{subscription.category}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-6">
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">ID</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<code className="text-sm">{subscription.id}</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">Category</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<Badge variant="outline">{subscription.category}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">Display Name</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<span className="text-sm">
|
||||
{subscription.displayName || 'Not set'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">Enabled</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<Badge
|
||||
variant={subscription.enabled ? 'default' : 'secondary'}
|
||||
>
|
||||
{subscription.enabled ? 'Enabled' : 'Disabled'}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{subscription.credential3rd && (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">Credential ID</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<code className="text-sm">
|
||||
{subscription.credential3rd.id}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">
|
||||
Credential Username
|
||||
</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<code className="text-sm">
|
||||
{subscription.credential3rd.username}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<Separator />
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">Source URL</Label>
|
||||
<div className="flex items-center justify-between rounded-md bg-muted p-3">
|
||||
<span className="break-all text-sm">
|
||||
{subscription.sourceUrl || '-'}
|
||||
</span>
|
||||
{subscription.sourceUrl && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="ml-2 h-6 w-6 p-0"
|
||||
onClick={() =>
|
||||
window.open(subscription.sourceUrl, '_blank')
|
||||
}
|
||||
>
|
||||
<ExternalLink className="h-3 w-3" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
{sourceUrlMeta?.category ===
|
||||
SubscriptionCategoryEnum.MikanSeason && (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">Year</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<code className="text-sm">{sourceUrlMeta.year}</code>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">Season</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<code className="text-sm">{sourceUrlMeta.seasonStr}</code>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<Separator />
|
||||
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">Created at</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<span className="text-sm">
|
||||
{format(
|
||||
new Date(subscription.createdAt),
|
||||
'yyyy-MM-dd HH:mm:ss'
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-sm">Updated at</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<span className="text-sm">
|
||||
{format(
|
||||
new Date(subscription.updatedAt),
|
||||
'yyyy-MM-dd HH:mm:ss'
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{subscription.bangumi?.nodes &&
|
||||
subscription.bangumi.nodes.length > 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<div className="space-y-4">
|
||||
<Label className="font-medium text-sm">
|
||||
Associated Bangumi
|
||||
</Label>
|
||||
<div className="space-y-3">
|
||||
{subscription.bangumi.nodes.map((bangumi) => (
|
||||
<Card key={bangumi.id} className="p-4">
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-muted-foreground text-xs">
|
||||
Display Name
|
||||
</Label>
|
||||
<div className="text-sm">
|
||||
{bangumi.displayName}
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-muted-foreground text-xs">
|
||||
Season
|
||||
</Label>
|
||||
<div className="text-sm">
|
||||
{bangumi.season || '-'}
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-muted-foreground text-xs">
|
||||
Fansub
|
||||
</Label>
|
||||
<div className="text-sm">
|
||||
{bangumi.fansub || '-'}
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label className="font-medium text-muted-foreground text-xs">
|
||||
Save Path
|
||||
</Label>
|
||||
<div className="font-mono text-sm">
|
||||
{bangumi.savePath || '-'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{bangumi.homepage && (
|
||||
<div className="mt-3 border-t pt-3">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
window.open(bangumi.homepage!, '_blank')
|
||||
}
|
||||
>
|
||||
<ExternalLink className="mr-2 h-3 w-3" />
|
||||
Homepage
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -1,14 +1,414 @@
|
||||
import { DetailCardSkeleton } from '@/components/detail-card-skeleton';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { DetailEmptyView } from '@/components/ui/detail-empty-view';
|
||||
import { FormFieldErrors } from '@/components/ui/form-field-errors';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { QueryErrorView } from '@/components/ui/query-error-view';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { useAppForm } from '@/components/ui/tanstack-form';
|
||||
import { MikanSeasonEnum } from '@/domains/recorder/schema/mikan';
|
||||
import {
|
||||
GET_SUBSCRIPTION_DETAIL,
|
||||
type SubscriptionInsertForm,
|
||||
SubscriptionInsertFormSchema,
|
||||
UPDATE_SUBSCRIPTIONS,
|
||||
} from '@/domains/recorder/schema/subscriptions';
|
||||
import { SubscriptionService } from '@/domains/recorder/services/subscription.service';
|
||||
import { useInject } from '@/infra/di/inject';
|
||||
import {
|
||||
Credential3rdTypeEnum,
|
||||
type GetSubscriptionDetailQuery,
|
||||
SubscriptionCategoryEnum,
|
||||
type UpdateSubscriptionsMutation,
|
||||
type UpdateSubscriptionsMutationVariables,
|
||||
} from '@/infra/graphql/gql/graphql';
|
||||
import type { RouteStateDataOption } from '@/infra/routes/traits';
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import { useMutation, useQuery } from '@apollo/client';
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router';
|
||||
import { ArrowLeft, Save, X } from 'lucide-react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import { Credential3rdSelectContent } from './-credential3rd-select';
|
||||
|
||||
export const Route = createFileRoute('/_app/subscriptions/edit/$id')({
|
||||
component: RouteComponent,
|
||||
component: SubscriptionEditRouteComponent,
|
||||
staticData: {
|
||||
breadcrumb: { label: 'Edit' },
|
||||
} satisfies RouteStateDataOption,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
const { id } = Route.useParams();
|
||||
return <div>Hello "/subscriptions/edit/$id"!</div>;
|
||||
type SubscriptionDetailDto = NonNullable<
|
||||
GetSubscriptionDetailQuery['subscriptions']['nodes'][0]
|
||||
>;
|
||||
|
||||
function FormView({
|
||||
subscription,
|
||||
onCompleted,
|
||||
}: {
|
||||
subscription: SubscriptionDetailDto;
|
||||
onCompleted: VoidFunction;
|
||||
}) {
|
||||
const navigate = useNavigate();
|
||||
const subscriptionService = useInject(SubscriptionService);
|
||||
|
||||
const handleBack = () => {
|
||||
navigate({
|
||||
to: '/subscriptions/detail/$id',
|
||||
params: { id: subscription.id.toString() },
|
||||
});
|
||||
};
|
||||
|
||||
const [updateSubscription, { loading: updating }] = useMutation<
|
||||
UpdateSubscriptionsMutation,
|
||||
UpdateSubscriptionsMutationVariables
|
||||
>(UPDATE_SUBSCRIPTIONS, {
|
||||
onCompleted,
|
||||
onError: (error) => {
|
||||
toast.error('Update subscription failed', {
|
||||
description: error.message,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// Extract source URL metadata for form initialization
|
||||
const sourceUrlMeta = useMemo(
|
||||
() =>
|
||||
subscriptionService.extractSourceUrlMeta(
|
||||
subscription.category,
|
||||
subscription.sourceUrl
|
||||
),
|
||||
[subscription.category, subscription.sourceUrl, subscriptionService]
|
||||
);
|
||||
|
||||
// Initialize form with current subscription data
|
||||
const defaultValues = useMemo(() => {
|
||||
const base = {
|
||||
displayName: subscription.displayName,
|
||||
category: subscription.category,
|
||||
enabled: subscription.enabled,
|
||||
sourceUrl: subscription.sourceUrl,
|
||||
credentialId: subscription.credential3rd?.id || '',
|
||||
};
|
||||
|
||||
if (
|
||||
subscription.category === SubscriptionCategoryEnum.MikanSeason &&
|
||||
sourceUrlMeta?.category === SubscriptionCategoryEnum.MikanSeason
|
||||
) {
|
||||
return {
|
||||
...base,
|
||||
year: sourceUrlMeta.year,
|
||||
seasonStr: sourceUrlMeta.seasonStr,
|
||||
};
|
||||
}
|
||||
|
||||
return base;
|
||||
}, [subscription, sourceUrlMeta]);
|
||||
|
||||
const form = useAppForm({
|
||||
defaultValues: defaultValues as unknown as SubscriptionInsertForm,
|
||||
validators: {
|
||||
onChangeAsync: SubscriptionInsertFormSchema,
|
||||
onChangeAsyncDebounceMs: 300,
|
||||
onSubmit: SubscriptionInsertFormSchema,
|
||||
},
|
||||
onSubmit: async (form) => {
|
||||
const input = subscriptionService.transformInsertFormToInput(form.value);
|
||||
|
||||
await updateSubscription({
|
||||
variables: {
|
||||
data: input,
|
||||
filters: {
|
||||
id: {
|
||||
eq: subscription.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="container mx-auto max-w-4xl py-6">
|
||||
<div className="mb-6 flex items-center justify-between">
|
||||
<div className="flex items-center gap-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleBack}
|
||||
className="h-8 w-8 p-0"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<div>
|
||||
<h1 className="font-bold text-2xl">Subscription edit</h1>
|
||||
<p className="mt-1 text-muted-foreground">
|
||||
Edit subscription #{subscription.id}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={handleBack} disabled={updating}>
|
||||
<X className="mr-2 h-4 w-4" />
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={() => form.handleSubmit()} disabled={updating}>
|
||||
<Save className="mr-2 h-4 w-4" />
|
||||
{updating ? 'Saving...' : 'Save'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<CardTitle>Subscription information</CardTitle>
|
||||
<CardDescription className="mt-2">
|
||||
Edit subscription information
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Badge variant="outline">{subscription.category}</Badge>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
form.handleSubmit();
|
||||
}}
|
||||
className="space-y-6"
|
||||
>
|
||||
<form.Field name="displayName">
|
||||
{(field) => (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={field.name}>Display Name *</Label>
|
||||
<Input
|
||||
id={field.name}
|
||||
name={field.name}
|
||||
value={field.state.value}
|
||||
onBlur={field.handleBlur}
|
||||
onChange={(e) => field.handleChange(e.target.value)}
|
||||
placeholder="Please enter display name"
|
||||
autoComplete="off"
|
||||
/>
|
||||
{field.state.meta.errors && (
|
||||
<FormFieldErrors
|
||||
errors={field.state.meta.errors}
|
||||
isDirty={field.state.meta.isDirty}
|
||||
submissionAttempts={form.state.submissionAttempts}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
|
||||
{/* Category is read-only in edit mode */}
|
||||
<div className="space-y-2">
|
||||
<Label>Category</Label>
|
||||
<div className="rounded-md bg-muted p-3">
|
||||
<Badge variant="outline">{subscription.category}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Conditional fields based on category */}
|
||||
{subscription.category === SubscriptionCategoryEnum.MikanSeason ? (
|
||||
<>
|
||||
<form.Field name="credentialId">
|
||||
{(field) => (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={field.name}>Credential ID *</Label>
|
||||
<Select
|
||||
value={field.state.value.toString()}
|
||||
onValueChange={(value) =>
|
||||
field.handleChange(Number.parseInt(value))
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select credential" />
|
||||
</SelectTrigger>
|
||||
<Credential3rdSelectContent
|
||||
credentialType={Credential3rdTypeEnum.Mikan}
|
||||
/>
|
||||
</Select>
|
||||
{field.state.meta.errors && (
|
||||
<FormFieldErrors
|
||||
errors={field.state.meta.errors}
|
||||
isDirty={field.state.meta.isDirty}
|
||||
submissionAttempts={form.state.submissionAttempts}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
<form.Field name="year">
|
||||
{(field) => (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={field.name}>Year *</Label>
|
||||
<Input
|
||||
id={field.name}
|
||||
name={field.name}
|
||||
value={field.state.value}
|
||||
type="number"
|
||||
min={1970}
|
||||
onBlur={field.handleBlur}
|
||||
onChange={(e) =>
|
||||
field.handleChange(Number.parseInt(e.target.value))
|
||||
}
|
||||
placeholder={`Please enter full year (e.g. ${new Date().getFullYear()})`}
|
||||
autoComplete="off"
|
||||
/>
|
||||
{field.state.meta.errors && (
|
||||
<FormFieldErrors
|
||||
errors={field.state.meta.errors}
|
||||
isDirty={field.state.meta.isDirty}
|
||||
submissionAttempts={form.state.submissionAttempts}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
<form.Field name="seasonStr">
|
||||
{(field) => (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={field.name}>Season *</Label>
|
||||
<Select
|
||||
value={field.state.value}
|
||||
onValueChange={(value) =>
|
||||
field.handleChange(value as MikanSeasonEnum)
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select season" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={MikanSeasonEnum.Spring}>
|
||||
Spring
|
||||
</SelectItem>
|
||||
<SelectItem value={MikanSeasonEnum.Summer}>
|
||||
Summer
|
||||
</SelectItem>
|
||||
<SelectItem value={MikanSeasonEnum.Autumn}>
|
||||
Autumn
|
||||
</SelectItem>
|
||||
<SelectItem value={MikanSeasonEnum.Winter}>
|
||||
Winter
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{field.state.meta.errors && (
|
||||
<FormFieldErrors
|
||||
errors={field.state.meta.errors}
|
||||
isDirty={field.state.meta.isDirty}
|
||||
submissionAttempts={form.state.submissionAttempts}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
</>
|
||||
) : (
|
||||
<form.Field name="sourceUrl">
|
||||
{(field) => (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={field.name}>Source URL *</Label>
|
||||
<Input
|
||||
id={field.name}
|
||||
name={field.name}
|
||||
value={field.state.value}
|
||||
onBlur={field.handleBlur}
|
||||
onChange={(e) => field.handleChange(e.target.value)}
|
||||
placeholder="Please enter source URL"
|
||||
autoComplete="off"
|
||||
/>
|
||||
{field.state.meta.errors && (
|
||||
<FormFieldErrors
|
||||
errors={field.state.meta.errors}
|
||||
isDirty={field.state.meta.isDirty}
|
||||
submissionAttempts={form.state.submissionAttempts}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
)}
|
||||
|
||||
<form.Field name="enabled">
|
||||
{(field) => (
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor={field.name}>Enabled</Label>
|
||||
<div className="text-muted-foreground text-sm">
|
||||
Enable this subscription
|
||||
</div>
|
||||
</div>
|
||||
<Switch
|
||||
id={field.name}
|
||||
checked={field.state.value}
|
||||
onCheckedChange={(checked) => field.handleChange(checked)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SubscriptionEditRouteComponent() {
|
||||
const { id } = Route.useParams();
|
||||
|
||||
const { loading, error, data, refetch } =
|
||||
useQuery<GetSubscriptionDetailQuery>(GET_SUBSCRIPTION_DETAIL, {
|
||||
variables: {
|
||||
id: Number.parseInt(id),
|
||||
},
|
||||
fetchPolicy: 'cache-and-network',
|
||||
});
|
||||
|
||||
const subscription = data?.subscriptions?.nodes?.[0];
|
||||
|
||||
const onCompleted = useCallback(async () => {
|
||||
const refetchResult = await refetch();
|
||||
if (refetchResult.errors) {
|
||||
toast.error('Update subscription failed', {
|
||||
description: refetchResult.errors[0].message,
|
||||
});
|
||||
} else {
|
||||
toast.success('Update subscription successfully');
|
||||
}
|
||||
}, [refetch]);
|
||||
|
||||
if (loading) {
|
||||
return <DetailCardSkeleton />;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <QueryErrorView message={error.message} />;
|
||||
}
|
||||
|
||||
if (!subscription) {
|
||||
return <DetailEmptyView message="Not found certain subscription" />;
|
||||
}
|
||||
|
||||
return <FormView subscription={subscription} onCompleted={onCompleted} />;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ function SubscriptionManageRouteComponent() {
|
||||
variables: {
|
||||
pagination: {
|
||||
page: {
|
||||
page: pagination.pageIndex + 1,
|
||||
page: pagination.pageIndex,
|
||||
limit: pagination.pageSize,
|
||||
},
|
||||
},
|
||||
|
18
pnpm-lock.yaml
generated
18
pnpm-lock.yaml
generated
@ -224,6 +224,9 @@ importers:
|
||||
jotai-signal:
|
||||
specifier: ^0.9.0
|
||||
version: 0.9.0(jotai@2.12.5(@types/react@19.1.6)(react@19.1.0))(react@19.1.0)
|
||||
lodash-es:
|
||||
specifier: ^4.17.21
|
||||
version: 4.17.21
|
||||
lucide-react:
|
||||
specifier: ^0.512.0
|
||||
version: 0.512.0(react@19.1.0)
|
||||
@ -291,6 +294,9 @@ importers:
|
||||
'@tanstack/router-plugin':
|
||||
specifier: ^1.112.13
|
||||
version: 1.120.15(@rsbuild/core@1.3.22)(@tanstack/react-router@1.120.15(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(vite@5.4.11(@types/node@22.15.29)(lightningcss@1.30.1)(sass@1.77.4)(terser@5.41.0))(webpack@5.97.1)
|
||||
'@types/lodash-es':
|
||||
specifier: ^4.17.12
|
||||
version: 4.17.12
|
||||
'@types/react':
|
||||
specifier: ^19.1.2
|
||||
version: 19.1.6
|
||||
@ -3509,6 +3515,9 @@ packages:
|
||||
'@types/json-schema@7.0.15':
|
||||
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
|
||||
|
||||
'@types/lodash-es@4.17.12':
|
||||
resolution: {integrity: sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==}
|
||||
|
||||
'@types/lodash.merge@4.6.9':
|
||||
resolution: {integrity: sha512-23sHDPmzd59kUgWyKGiOMO2Qb9YtqRO/x4IhkgNUiPQ1+5MUVqi6bCZeq9nBJ17msjIMbEIO5u+XW4Kz6aGUhQ==}
|
||||
|
||||
@ -5428,6 +5437,9 @@ packages:
|
||||
resolution: {integrity: sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
lodash-es@4.17.21:
|
||||
resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==}
|
||||
|
||||
lodash.chunk@4.2.0:
|
||||
resolution: {integrity: sha512-ZzydJKfUHJwHa+hF5X66zLFCBrWn5GeF28OHEr4WVWtNDXlQ/IjWKPBiikqKo2ne0+v6JgCgJ0GzJp8k8bHC7w==}
|
||||
|
||||
@ -10673,6 +10685,10 @@ snapshots:
|
||||
'@types/json-schema@7.0.15':
|
||||
optional: true
|
||||
|
||||
'@types/lodash-es@4.17.12':
|
||||
dependencies:
|
||||
'@types/lodash': 4.17.13
|
||||
|
||||
'@types/lodash.merge@4.6.9':
|
||||
dependencies:
|
||||
'@types/lodash': 4.17.13
|
||||
@ -12880,6 +12896,8 @@ snapshots:
|
||||
dependencies:
|
||||
p-locate: 4.1.0
|
||||
|
||||
lodash-es@4.17.21: {}
|
||||
|
||||
lodash.chunk@4.2.0: {}
|
||||
|
||||
lodash.get@4.4.2: {}
|
||||
|
Loading…
Reference in New Issue
Block a user