docs/.vitepress/types/Feedback.ts
68 lines · 1647 bytes
1/**
2 * Copyright (c) 2024 taskylizard
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import z from 'zod'
17
18export const FeedbackSchema = z.object({
19 message: z.string().min(5).max(1000),
20 type: z.enum([
21 'submit',
22 'update',
23 'report',
24 'suggestion',
25 'appreciation',
26 'other'
27 ]),
28 page: z.string().url(),
29 // For heading based feedback
30 heading: z.string().min(3).max(20).optional()
31})
32
33export interface Option {
34 label: string
35 value: FeedbackType['type']
36}
37
38export const feedbackOptions: Option[] = [
39 {
40 label: '➕ Submit link',
41 value: 'submit'
42 },
43 {
44 label: '❗️ Update link',
45 value: 'update'
46 },
47 {
48 label: '❌ Report bad / dead link',
49 value: 'report'
50 },
51 {
52 label: '💡 Suggest edit',
53 value: 'suggestion'
54 },
55 {
56 label: '❤️ Love the wiki',
57 value: 'appreciation'
58 },
59 { label: '💬 Something else', value: 'other' }
60]
61
62export function getFeedbackOption(
63 value: FeedbackType['type']
64): Option | undefined {
65 return feedbackOptions.find((option) => option.value === value)
66}
67
68export type FeedbackType = z.infer<typeof FeedbackSchema>