refactor: 统一前端业务提供项命名
This commit is contained in:
1 parent
88cd8df40e
commit
a374614313
3 files changed
+23
-24
No files matched your search
@@ -13,7 +13,7 @@ import {
|
|||||||
Divider,
|
Divider,
|
||||||
} from "antd";
|
} from "antd";
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import type { Offering, PublicService } from "@personal-brand/api-client";
|
import type { Offering, PublicOffering } from "@personal-brand/api-client";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { createApiClient } from "../../lib/api.js";
|
import { createApiClient } from "../../lib/api.js";
|
||||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||||
@@ -22,15 +22,15 @@ import { MutationError, QueryState } from "../../components/QueryState.js";
|
|||||||
export function ServicesPage() {
|
export function ServicesPage() {
|
||||||
const client = createApiClient();
|
const client = createApiClient();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [editing, setEditing] = useState<PublicService | null>(null);
|
const [editing, setEditing] = useState<PublicOffering | null>(null);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [offeringForm] = Form.useForm();
|
const [offeringForm] = Form.useForm();
|
||||||
const [offeringOpen, setOfferingOpen] = useState(false);
|
const [offeringOpen, setOfferingOpen] = useState(false);
|
||||||
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: ["admin-services"],
|
queryKey: ["admin-offerings-compat"],
|
||||||
queryFn: () => client.listAdminServices(),
|
queryFn: () => client.listAdminOfferingsCompat(),
|
||||||
});
|
});
|
||||||
const offerings = useQuery({
|
const offerings = useQuery({
|
||||||
queryKey: ["admin-offerings"],
|
queryKey: ["admin-offerings"],
|
||||||
@@ -52,25 +52,25 @@ export function ServicesPage() {
|
|||||||
const save = useMutation({
|
const save = useMutation({
|
||||||
mutationFn: (values: Record<string, unknown>) =>
|
mutationFn: (values: Record<string, unknown>) =>
|
||||||
editing
|
editing
|
||||||
? client.updateAdminService(editing.id, values)
|
? client.updateAdminOfferingCompat(editing.id, values)
|
||||||
: client.createAdminService(values as { name: string; description: string }),
|
: client.createAdminOfferingCompat(values as { name: string; description: string }),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
message.success("服务已保存");
|
message.success("服务已保存");
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
setEditing(null);
|
setEditing(null);
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
void queryClient.invalidateQueries({ queryKey: ["admin-services"] });
|
void queryClient.invalidateQueries({ queryKey: ["admin-offerings-compat"] });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const toggle = useMutation({
|
const toggle = useMutation({
|
||||||
mutationFn: (item: PublicService) =>
|
mutationFn: (item: PublicOffering) =>
|
||||||
client.updateAdminService(item.id, { isEnabled: !item.isEnabled }),
|
client.updateAdminOfferingCompat(item.id, { isEnabled: !item.isEnabled }),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
message.success("服务状态已更新");
|
message.success("服务状态已更新");
|
||||||
void queryClient.invalidateQueries({ queryKey: ["admin-services"] });
|
void queryClient.invalidateQueries({ queryKey: ["admin-offerings-compat"] });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const begin = (item?: PublicService) => {
|
const begin = (item?: PublicOffering) => {
|
||||||
setEditing(item ?? null);
|
setEditing(item ?? null);
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
form.setFieldsValue(
|
form.setFieldsValue(
|
||||||
@@ -170,7 +170,7 @@ export function ServicesPage() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "操作",
|
title: "操作",
|
||||||
render: (_: unknown, item: PublicService) => (
|
render: (_: unknown, item: PublicOffering) => (
|
||||||
<Space>
|
<Space>
|
||||||
<Button size="small" onClick={() => begin(item)}>
|
<Button size="small" onClick={() => begin(item)}>
|
||||||
编辑
|
编辑
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import type {
|
|||||||
BookingStatus,
|
BookingStatus,
|
||||||
ContactPreference,
|
ContactPreference,
|
||||||
FulfillmentType,
|
FulfillmentType,
|
||||||
PublicService,
|
PublicOffering,
|
||||||
BrandTemplateKey,
|
BrandTemplateKey,
|
||||||
} from "@personal-brand/types";
|
} from "@personal-brand/types";
|
||||||
export type { PublicService } from "@personal-brand/types";
|
export type { PublicOffering } from "@personal-brand/types";
|
||||||
export type { BookingStatus } from "@personal-brand/types";
|
export type { BookingStatus } from "@personal-brand/types";
|
||||||
|
|
||||||
export interface BrandProfile {
|
export interface BrandProfile {
|
||||||
@@ -25,7 +25,7 @@ export interface BrandProfile {
|
|||||||
config?: Record<string, unknown> | null;
|
config?: Record<string, unknown> | null;
|
||||||
}
|
}
|
||||||
export type BrandUpdate = Partial<Omit<BrandProfile, "id">>;
|
export type BrandUpdate = Partial<Omit<BrandProfile, "id">>;
|
||||||
export interface ServiceUpdate {
|
export interface OfferingUpdate {
|
||||||
name?: string;
|
name?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
coverUrl?: string;
|
coverUrl?: string;
|
||||||
@@ -37,7 +37,6 @@ export interface ServiceUpdate {
|
|||||||
categoryKey?: string;
|
categoryKey?: string;
|
||||||
config?: Record<string, unknown>;
|
config?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
export type OfferingUpdate = ServiceUpdate;
|
|
||||||
export interface TrustContent {
|
export interface TrustContent {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
@@ -271,7 +270,7 @@ export class ApiClient {
|
|||||||
getBrand(): Promise<BrandProfile> {
|
getBrand(): Promise<BrandProfile> {
|
||||||
return this.request("/public/brand");
|
return this.request("/public/brand");
|
||||||
}
|
}
|
||||||
listServices(): Promise<PublicService[]> {
|
listOfferings(): Promise<PublicOffering[]> {
|
||||||
return this.request("/public/offerings");
|
return this.request("/public/offerings");
|
||||||
}
|
}
|
||||||
getPublicWorkspace(): Promise<PublicWorkspace> {
|
getPublicWorkspace(): Promise<PublicWorkspace> {
|
||||||
@@ -440,19 +439,19 @@ export class ApiClient {
|
|||||||
body,
|
body,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
updateAdminService(id: string, body: ServiceUpdate): Promise<PublicService> {
|
updateAdminOfferingCompat(id: string, body: OfferingUpdate): Promise<PublicOffering> {
|
||||||
const { categoryKey, ...rest } = body;
|
const { categoryKey, ...rest } = body;
|
||||||
return this.request(`/admin/workspace/offerings/${encodeURIComponent(id)}`, {
|
return this.request(`/admin/workspace/offerings/${encodeURIComponent(id)}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
body: { ...rest, ...(categoryKey ? { kind: categoryKey } : {}) },
|
body: { ...rest, ...(categoryKey ? { kind: categoryKey } : {}) },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
listAdminServices(): Promise<PublicService[]> {
|
listAdminOfferingsCompat(): Promise<PublicOffering[]> {
|
||||||
return this.request("/admin/workspace/offerings");
|
return this.request("/admin/workspace/offerings");
|
||||||
}
|
}
|
||||||
createAdminService(
|
createAdminOfferingCompat(
|
||||||
body: ServiceUpdate & { name: string; description: string },
|
body: OfferingUpdate & { name: string; description: string },
|
||||||
): Promise<PublicService> {
|
): Promise<PublicOffering> {
|
||||||
const { categoryKey, bookingEnabled: _bookingEnabled, ...rest } = body;
|
const { categoryKey, bookingEnabled: _bookingEnabled, ...rest } = body;
|
||||||
return this.request("/admin/workspace/offerings", {
|
return this.request("/admin/workspace/offerings", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const BOOKING_STATUS = {
|
|||||||
CANCELLED: "cancelled",
|
CANCELLED: "cancelled",
|
||||||
} as const satisfies Record<Uppercase<BookingStatus>, BookingStatus>;
|
} as const satisfies Record<Uppercase<BookingStatus>, BookingStatus>;
|
||||||
|
|
||||||
export interface PublicService {
|
export interface PublicOffering {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
@@ -38,4 +38,4 @@ export interface PublicService {
|
|||||||
categoryKey?: string;
|
categoryKey?: string;
|
||||||
config?: Record<string, unknown> | null;
|
config?: Record<string, unknown> | null;
|
||||||
}
|
}
|
||||||
export type PublicOffering = PublicService;
|
export type PublicService = PublicOffering;
|
||||||
Reference in new issue
Block a user