@dappermountain/payload-plugin-achievements 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/admin/LucideIconField.d.ts +1 -0
- package/dist/admin/LucideIconField.d.ts.map +1 -1
- package/dist/admin/LucideIconField.js +54 -101
- package/dist/admin/ReconcileProgressionButton.d.ts +1 -1
- package/dist/admin/ReconcileProgressionButton.d.ts.map +1 -1
- package/dist/admin/ReconcileProgressionButton.js +21 -7
- package/dist/admin/useEventTypeFlags.d.ts.map +1 -1
- package/dist/admin/useEventTypeFlags.js +7 -4
- package/dist/admin/usePluginT.d.ts +6 -0
- package/dist/admin/usePluginT.d.ts.map +1 -0
- package/dist/admin/usePluginT.js +10 -0
- package/dist/adminLabel.d.ts +17 -0
- package/dist/adminLabel.d.ts.map +1 -0
- package/dist/adminLabel.js +28 -0
- package/dist/collections/AchievementRequests/hooks/prepareAchievementRequest.d.ts.map +1 -1
- package/dist/collections/AchievementRequests/hooks/prepareAchievementRequest.js +8 -7
- package/dist/collections/AchievementRequests/index.d.ts.map +1 -1
- package/dist/collections/AchievementRequests/index.js +19 -5
- package/dist/collections/Achievements/index.d.ts.map +1 -1
- package/dist/collections/Achievements/index.js +17 -13
- package/dist/collections/EventTypes/index.d.ts.map +1 -1
- package/dist/collections/EventTypes/index.js +26 -12
- package/dist/collections/Grants/hooks/ensureUniqueGrant.js +2 -2
- package/dist/collections/Grants/index.d.ts.map +1 -1
- package/dist/collections/Grants/index.js +25 -16
- package/dist/collections/Logs/fields/validators.d.ts.map +1 -1
- package/dist/collections/Logs/fields/validators.js +8 -7
- package/dist/collections/Logs/hooks/ensureTypeRequirements.d.ts.map +1 -1
- package/dist/collections/Logs/hooks/ensureTypeRequirements.js +9 -7
- package/dist/collections/Logs/index.d.ts.map +1 -1
- package/dist/collections/Logs/index.js +33 -15
- package/dist/collections/MetricBalances/index.d.ts.map +1 -1
- package/dist/collections/MetricBalances/index.js +9 -3
- package/dist/collections/Metrics/index.d.ts.map +1 -1
- package/dist/collections/Metrics/index.js +35 -16
- package/dist/collections/Reactions/index.d.ts.map +1 -1
- package/dist/collections/Reactions/index.js +25 -13
- package/dist/collections/TierRequests/hooks/prepareTierRequest.d.ts.map +1 -1
- package/dist/collections/TierRequests/hooks/prepareTierRequest.js +8 -7
- package/dist/collections/TierRequests/index.d.ts.map +1 -1
- package/dist/collections/TierRequests/index.js +13 -7
- package/dist/collections/Tiers/index.d.ts.map +1 -1
- package/dist/collections/Tiers/index.js +17 -7
- package/dist/collections/fields/localizedText.d.ts.map +1 -1
- package/dist/collections/fields/localizedText.js +3 -0
- package/dist/collections/fields/ruleFields.d.ts.map +1 -1
- package/dist/collections/fields/ruleFields.js +25 -16
- package/dist/collections/fields/scopeField.d.ts.map +1 -1
- package/dist/collections/fields/scopeField.js +3 -1
- package/dist/collections/fields/userField.d.ts.map +1 -1
- package/dist/collections/fields/userField.js +2 -0
- package/dist/collections/fields/usersAchievementsGroup.d.ts.map +1 -1
- package/dist/collections/fields/usersAchievementsGroup.js +2 -1
- package/dist/collections/helpers.d.ts.map +1 -1
- package/dist/collections/helpers.js +2 -1
- package/dist/collections/hooks/preventCatalogDelete.d.ts.map +1 -1
- package/dist/collections/hooks/preventCatalogDelete.js +6 -3
- package/dist/collections/slugs.d.ts +5 -2
- package/dist/collections/slugs.d.ts.map +1 -1
- package/dist/collections/slugs.js +7 -5
- package/dist/defaults.d.ts +1 -1
- package/dist/defaults.d.ts.map +1 -1
- package/dist/extensions/actions.d.ts.map +1 -1
- package/dist/extensions/actions.js +2 -1
- package/dist/extensions/elapsedSinceOptions.d.ts +1 -1
- package/dist/extensions/elapsedSinceOptions.d.ts.map +1 -1
- package/dist/extensions/elapsedSinceOptions.js +4 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +20 -0
- package/dist/translations/index.d.ts +8723 -0
- package/dist/translations/index.d.ts.map +1 -0
- package/dist/translations/index.js +96 -0
- package/dist/translations/keys.d.ts +4 -0
- package/dist/translations/keys.d.ts.map +1 -0
- package/dist/translations/keys.js +5 -0
- package/dist/translations/languages/ar.d.ts +199 -0
- package/dist/translations/languages/ar.d.ts.map +1 -0
- package/dist/translations/languages/ar.js +198 -0
- package/dist/translations/languages/az.d.ts +199 -0
- package/dist/translations/languages/az.d.ts.map +1 -0
- package/dist/translations/languages/az.js +198 -0
- package/dist/translations/languages/bg.d.ts +199 -0
- package/dist/translations/languages/bg.d.ts.map +1 -0
- package/dist/translations/languages/bg.js +198 -0
- package/dist/translations/languages/bnBd.d.ts +199 -0
- package/dist/translations/languages/bnBd.d.ts.map +1 -0
- package/dist/translations/languages/bnBd.js +198 -0
- package/dist/translations/languages/bnIn.d.ts +199 -0
- package/dist/translations/languages/bnIn.d.ts.map +1 -0
- package/dist/translations/languages/bnIn.js +198 -0
- package/dist/translations/languages/ca.d.ts +199 -0
- package/dist/translations/languages/ca.d.ts.map +1 -0
- package/dist/translations/languages/ca.js +198 -0
- package/dist/translations/languages/cs.d.ts +199 -0
- package/dist/translations/languages/cs.d.ts.map +1 -0
- package/dist/translations/languages/cs.js +198 -0
- package/dist/translations/languages/da.d.ts +199 -0
- package/dist/translations/languages/da.d.ts.map +1 -0
- package/dist/translations/languages/da.js +198 -0
- package/dist/translations/languages/de.d.ts +199 -0
- package/dist/translations/languages/de.d.ts.map +1 -0
- package/dist/translations/languages/de.js +198 -0
- package/dist/translations/languages/en.d.ts +199 -0
- package/dist/translations/languages/en.d.ts.map +1 -0
- package/dist/translations/languages/en.js +198 -0
- package/dist/translations/languages/es.d.ts +199 -0
- package/dist/translations/languages/es.d.ts.map +1 -0
- package/dist/translations/languages/es.js +198 -0
- package/dist/translations/languages/et.d.ts +199 -0
- package/dist/translations/languages/et.d.ts.map +1 -0
- package/dist/translations/languages/et.js +198 -0
- package/dist/translations/languages/fa.d.ts +199 -0
- package/dist/translations/languages/fa.d.ts.map +1 -0
- package/dist/translations/languages/fa.js +198 -0
- package/dist/translations/languages/fr.d.ts +199 -0
- package/dist/translations/languages/fr.d.ts.map +1 -0
- package/dist/translations/languages/fr.js +198 -0
- package/dist/translations/languages/he.d.ts +199 -0
- package/dist/translations/languages/he.d.ts.map +1 -0
- package/dist/translations/languages/he.js +198 -0
- package/dist/translations/languages/hr.d.ts +199 -0
- package/dist/translations/languages/hr.d.ts.map +1 -0
- package/dist/translations/languages/hr.js +198 -0
- package/dist/translations/languages/hu.d.ts +199 -0
- package/dist/translations/languages/hu.d.ts.map +1 -0
- package/dist/translations/languages/hu.js +198 -0
- package/dist/translations/languages/hy.d.ts +199 -0
- package/dist/translations/languages/hy.d.ts.map +1 -0
- package/dist/translations/languages/hy.js +198 -0
- package/dist/translations/languages/id.d.ts +199 -0
- package/dist/translations/languages/id.d.ts.map +1 -0
- package/dist/translations/languages/id.js +198 -0
- package/dist/translations/languages/is.d.ts +199 -0
- package/dist/translations/languages/is.d.ts.map +1 -0
- package/dist/translations/languages/is.js +198 -0
- package/dist/translations/languages/it.d.ts +199 -0
- package/dist/translations/languages/it.d.ts.map +1 -0
- package/dist/translations/languages/it.js +198 -0
- package/dist/translations/languages/ja.d.ts +199 -0
- package/dist/translations/languages/ja.d.ts.map +1 -0
- package/dist/translations/languages/ja.js +198 -0
- package/dist/translations/languages/ko.d.ts +199 -0
- package/dist/translations/languages/ko.d.ts.map +1 -0
- package/dist/translations/languages/ko.js +198 -0
- package/dist/translations/languages/lt.d.ts +199 -0
- package/dist/translations/languages/lt.d.ts.map +1 -0
- package/dist/translations/languages/lt.js +198 -0
- package/dist/translations/languages/lv.d.ts +199 -0
- package/dist/translations/languages/lv.d.ts.map +1 -0
- package/dist/translations/languages/lv.js +198 -0
- package/dist/translations/languages/my.d.ts +199 -0
- package/dist/translations/languages/my.d.ts.map +1 -0
- package/dist/translations/languages/my.js +198 -0
- package/dist/translations/languages/nb.d.ts +199 -0
- package/dist/translations/languages/nb.d.ts.map +1 -0
- package/dist/translations/languages/nb.js +198 -0
- package/dist/translations/languages/nl.d.ts +199 -0
- package/dist/translations/languages/nl.d.ts.map +1 -0
- package/dist/translations/languages/nl.js +198 -0
- package/dist/translations/languages/pl.d.ts +199 -0
- package/dist/translations/languages/pl.d.ts.map +1 -0
- package/dist/translations/languages/pl.js +198 -0
- package/dist/translations/languages/pt.d.ts +199 -0
- package/dist/translations/languages/pt.d.ts.map +1 -0
- package/dist/translations/languages/pt.js +198 -0
- package/dist/translations/languages/ro.d.ts +199 -0
- package/dist/translations/languages/ro.d.ts.map +1 -0
- package/dist/translations/languages/ro.js +198 -0
- package/dist/translations/languages/rs.d.ts +199 -0
- package/dist/translations/languages/rs.d.ts.map +1 -0
- package/dist/translations/languages/rs.js +198 -0
- package/dist/translations/languages/rsLatin.d.ts +199 -0
- package/dist/translations/languages/rsLatin.d.ts.map +1 -0
- package/dist/translations/languages/rsLatin.js +198 -0
- package/dist/translations/languages/ru.d.ts +199 -0
- package/dist/translations/languages/ru.d.ts.map +1 -0
- package/dist/translations/languages/ru.js +198 -0
- package/dist/translations/languages/sk.d.ts +199 -0
- package/dist/translations/languages/sk.d.ts.map +1 -0
- package/dist/translations/languages/sk.js +198 -0
- package/dist/translations/languages/sl.d.ts +199 -0
- package/dist/translations/languages/sl.d.ts.map +1 -0
- package/dist/translations/languages/sl.js +198 -0
- package/dist/translations/languages/sv.d.ts +199 -0
- package/dist/translations/languages/sv.d.ts.map +1 -0
- package/dist/translations/languages/sv.js +198 -0
- package/dist/translations/languages/ta.d.ts +199 -0
- package/dist/translations/languages/ta.d.ts.map +1 -0
- package/dist/translations/languages/ta.js +198 -0
- package/dist/translations/languages/th.d.ts +199 -0
- package/dist/translations/languages/th.d.ts.map +1 -0
- package/dist/translations/languages/th.js +198 -0
- package/dist/translations/languages/tr.d.ts +199 -0
- package/dist/translations/languages/tr.d.ts.map +1 -0
- package/dist/translations/languages/tr.js +198 -0
- package/dist/translations/languages/uk.d.ts +199 -0
- package/dist/translations/languages/uk.d.ts.map +1 -0
- package/dist/translations/languages/uk.js +198 -0
- package/dist/translations/languages/vi.d.ts +199 -0
- package/dist/translations/languages/vi.d.ts.map +1 -0
- package/dist/translations/languages/vi.js +198 -0
- package/dist/translations/languages/zh.d.ts +199 -0
- package/dist/translations/languages/zh.d.ts.map +1 -0
- package/dist/translations/languages/zh.js +198 -0
- package/dist/translations/languages/zhTw.d.ts +199 -0
- package/dist/translations/languages/zhTw.d.ts.map +1 -0
- package/dist/translations/languages/zhTw.js +198 -0
- package/dist/translations/reqT.d.ts +14 -0
- package/dist/translations/reqT.d.ts.map +1 -0
- package/dist/translations/reqT.js +26 -0
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ You describe what people can earn and what has to happen first. Your app records
|
|
|
18
18
|
|
|
19
19
|
| Plugin line | Payload | Notes |
|
|
20
20
|
| ----------- | ------- | ----- |
|
|
21
|
-
| **`1.x`** (this package — e.g. `1.
|
|
21
|
+
| **`1.x`** (this package — e.g. `1.1.0`) | **4** (`^4.0.0-beta.1` / `^4.0.0`) | Current line. Opt out of P4 default versions/authorship on high-churn collections. |
|
|
22
22
|
| **`0.6.x`** | **3** (`^3.89`) | Last Payload 3 line. Same product features (reactions, composites, etc.). Stay on `0.6.x` until you upgrade the host to Payload 4. |
|
|
23
23
|
|
|
24
24
|
One published version cannot peer both Payload majors (Admin field types and collection defaults diverge). Pick the line that matches your host.
|
|
@@ -28,6 +28,7 @@ One published version cannot peer both Payload majors (Admin field types and col
|
|
|
28
28
|
- Payload `^4.0.0-beta.1` / `^4.0.0`
|
|
29
29
|
- `@payloadcms/ui` (same train as Payload)
|
|
30
30
|
- `@payloadcms/richtext-lexical` (same train as Payload)
|
|
31
|
+
- `@payloadcms/translations` (same train as Payload)
|
|
31
32
|
- `lucide-react` `^0.543`
|
|
32
33
|
- React `^19`
|
|
33
34
|
|
|
@@ -37,7 +38,7 @@ Plugin collections opt out of Payload 4’s default versions and authorship (app
|
|
|
37
38
|
|
|
38
39
|
```bash
|
|
39
40
|
# Payload 4 hosts
|
|
40
|
-
bun add @dappermountain/payload-plugin-achievements@^1.
|
|
41
|
+
bun add @dappermountain/payload-plugin-achievements@^1.1.0
|
|
41
42
|
|
|
42
43
|
# Payload 3 hosts (stay on the 0.6 line)
|
|
43
44
|
bun add @dappermountain/payload-plugin-achievements@0.6
|
|
@@ -308,7 +309,7 @@ Tier `icon` is a Lucide picker (stores `sparkles`, `shield`, …). Peer-depend o
|
|
|
308
309
|
|
|
309
310
|
`GET /api/achievements/me` and progress helpers return Lexical `description` as stored. Convert in your UI (`convertLexicalToHTML`, `convertLexicalToPlaintext`, or the plugin’s `descriptionToPlaintext` / `plainTextToLexical`).
|
|
310
311
|
|
|
311
|
-
Admin chrome
|
|
312
|
+
Admin chrome (collection labels, field labels and descriptions, select options, validation messages, and the plugin’s Admin components) uses Payload’s plugin i18n pattern: a `plugin-achievements` translation table merged into `config.i18n.translations` (same approach as Form Builder / PLUGIN-DEVELOPMENT). Labels resolve with `t('plugin-achievements:…')` via `tLabel` / `useTranslation().t`. Built-in strings ship for the same Admin language set as Form Builder / `@payloadcms/translations` (en, es, de, fr, …, zh-TW, and the rest); the plugin only merges languages present in the host’s `i18n.supportedLanguages` (default `en`). Hosts can override any key via `i18n.translations`. Export helpers: `tLabel`, `achievementsTranslations`, `achievementsKey`. Member-facing catalog copy (`name` / `description`) is CMS **localization**, not this UI dictionary. Seed extra locales after the English system catalog exists.
|
|
312
313
|
|
|
313
314
|
## Configuration
|
|
314
315
|
|
|
@@ -323,7 +324,7 @@ achievementPlugin({
|
|
|
323
324
|
slugPrefix?: string // deprecated; use collections.prefix
|
|
324
325
|
collections?: {
|
|
325
326
|
prefix?: string
|
|
326
|
-
adminGroup?: string | false
|
|
327
|
+
adminGroup?: string | false | Record<string, string> | (({ t }) => string)
|
|
327
328
|
slugs?: Partial<Record<AchievementCollectionKey, string>>
|
|
328
329
|
overrides?: Partial<Record<AchievementCollectionKey, AchievementCollectionOverride>>
|
|
329
330
|
}
|
|
@@ -357,7 +358,7 @@ achievementPlugin({
|
|
|
357
358
|
| Option | Default | Notes |
|
|
358
359
|
| --- | --- | --- |
|
|
359
360
|
| `prefix` | `'achievement'` | Default slugs, REST paths, and table names. |
|
|
360
|
-
| `adminGroup` | `'
|
|
361
|
+
| `adminGroup` | `t('plugin-achievements:adminGroup')` | Sidebar group (en: Achievements / es: Logros). Accepts a string, locale map, or label function. `false` leaves collections ungrouped. |
|
|
361
362
|
| `slugs` | derived | Absolute slug per key (ignores `prefix` for that key). |
|
|
362
363
|
| `overrides` | unset | `access`, `admin`, `hooks`, `labels`, `fields`. Access keys replace; hook arrays append after plugin hooks; `admin` / `labels` merge shallowly; `fields` replaces the list (use `({ defaultFields }) => …` to wrap). |
|
|
363
364
|
|
|
@@ -2,6 +2,7 @@ import type { TextFieldClientProps } from 'payload';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
/**
|
|
4
4
|
* Emoji-picker style Lucide field: searchable icon grid, stores kebab-case names.
|
|
5
|
+
* Trigger/clear/search use Payload Button / TextInput / Popup; the grid stays custom.
|
|
5
6
|
*/
|
|
6
7
|
export declare function LucideIconField(props: TextFieldClientProps): React.JSX.Element;
|
|
7
8
|
//# sourceMappingURL=LucideIconField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LucideIconField.d.ts","sourceRoot":"","sources":["../../src/admin/LucideIconField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"LucideIconField.d.ts","sourceRoot":"","sources":["../../src/admin/LucideIconField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAWnD,OAAO,KAA8E,MAAM,OAAO,CAAA;AA2DlG;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qBAkK1D"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { FieldDescription, FieldError, FieldLabel, useField } from '@payloadcms/ui';
|
|
3
|
+
import { Button, FieldDescription, FieldError, FieldLabel, Popup, TextInput, useField, } from '@payloadcms/ui';
|
|
4
4
|
import { icons } from 'lucide-react';
|
|
5
5
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { achievementsKey } from '../translations/keys.js';
|
|
7
|
+
import { usePluginT } from './usePluginT.js';
|
|
6
8
|
function toKebabCase(pascal) {
|
|
7
9
|
return pascal
|
|
8
10
|
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
@@ -25,12 +27,34 @@ const ALL_ICONS = Object.keys(icons)
|
|
|
25
27
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
26
28
|
const MAX_VISIBLE = 180;
|
|
27
29
|
const CELL = 36;
|
|
30
|
+
const pickerPanelStyle = {
|
|
31
|
+
display: 'flex',
|
|
32
|
+
flexDirection: 'column',
|
|
33
|
+
gap: '0.5rem',
|
|
34
|
+
maxWidth: 'min(360px, 100vw)',
|
|
35
|
+
padding: '0.15rem',
|
|
36
|
+
width: 360,
|
|
37
|
+
};
|
|
38
|
+
const iconGridStyle = {
|
|
39
|
+
display: 'grid',
|
|
40
|
+
gap: 4,
|
|
41
|
+
gridTemplateColumns: `repeat(auto-fill, minmax(${CELL}px, 1fr))`,
|
|
42
|
+
maxHeight: 260,
|
|
43
|
+
overflowY: 'auto',
|
|
44
|
+
paddingBottom: 4,
|
|
45
|
+
};
|
|
46
|
+
const footerStyle = {
|
|
47
|
+
color: 'var(--color-text-secondary)',
|
|
48
|
+
fontSize: 11,
|
|
49
|
+
};
|
|
28
50
|
/**
|
|
29
51
|
* Emoji-picker style Lucide field: searchable icon grid, stores kebab-case names.
|
|
52
|
+
* Trigger/clear/search use Payload Button / TextInput / Popup; the grid stays custom.
|
|
30
53
|
*/
|
|
31
54
|
export function LucideIconField(props) {
|
|
32
55
|
const { field, path: pathFromProps, readOnly } = props;
|
|
33
56
|
const path = pathFromProps ?? field?.name ?? 'icon';
|
|
57
|
+
const t = usePluginT();
|
|
34
58
|
const { errorMessage, setValue, showError, value } = useField({
|
|
35
59
|
path,
|
|
36
60
|
});
|
|
@@ -40,7 +64,6 @@ export function LucideIconField(props) {
|
|
|
40
64
|
: undefined;
|
|
41
65
|
const [open, setOpen] = useState(false);
|
|
42
66
|
const [query, setQuery] = useState('');
|
|
43
|
-
const rootRef = useRef(null);
|
|
44
67
|
const searchRef = useRef(null);
|
|
45
68
|
const filtered = useMemo(() => {
|
|
46
69
|
const q = query.trim().toLowerCase();
|
|
@@ -58,22 +81,7 @@ export function LucideIconField(props) {
|
|
|
58
81
|
useEffect(() => {
|
|
59
82
|
if (!open)
|
|
60
83
|
return;
|
|
61
|
-
const onPointerDown = (event) => {
|
|
62
|
-
if (!rootRef.current?.contains(event.target)) {
|
|
63
|
-
setOpen(false);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const onKeyDown = (event) => {
|
|
67
|
-
if (event.key === 'Escape')
|
|
68
|
-
setOpen(false);
|
|
69
|
-
};
|
|
70
|
-
document.addEventListener('mousedown', onPointerDown);
|
|
71
|
-
document.addEventListener('keydown', onKeyDown);
|
|
72
84
|
queueMicrotask(() => searchRef.current?.focus());
|
|
73
|
-
return () => {
|
|
74
|
-
document.removeEventListener('mousedown', onPointerDown);
|
|
75
|
-
document.removeEventListener('keydown', onKeyDown);
|
|
76
|
-
};
|
|
77
85
|
}, [open]);
|
|
78
86
|
const pick = useCallback((name) => {
|
|
79
87
|
setValue(name);
|
|
@@ -84,88 +92,33 @@ export function LucideIconField(props) {
|
|
|
84
92
|
setValue(null);
|
|
85
93
|
setQuery('');
|
|
86
94
|
}, [setValue]);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
border: '1px solid var(--theme-elevation-150)',
|
|
117
|
-
borderRadius: 'var(--style-radius-m, 6px)',
|
|
118
|
-
boxShadow: '0 8px 28px rgba(0,0,0,0.18)',
|
|
119
|
-
display: 'flex',
|
|
120
|
-
flexDirection: 'column',
|
|
121
|
-
left: 0,
|
|
122
|
-
maxWidth: 'min(360px, 100vw)',
|
|
123
|
-
padding: '0.65rem',
|
|
124
|
-
position: 'absolute',
|
|
125
|
-
top: 'calc(100% + 6px)',
|
|
126
|
-
width: 360,
|
|
127
|
-
zIndex: 40,
|
|
128
|
-
}, children: [_jsx("input", { "aria-label": "Search Lucide icons", onChange: (event) => setQuery(event.target.value), placeholder: "Search icons\u2026", ref: searchRef, style: {
|
|
129
|
-
background: 'var(--theme-input-bg)',
|
|
130
|
-
border: '1px solid var(--theme-elevation-150)',
|
|
131
|
-
borderRadius: 'var(--style-radius-s, 4px)',
|
|
132
|
-
color: 'var(--theme-text)',
|
|
133
|
-
fontSize: 13,
|
|
134
|
-
marginBottom: '0.5rem',
|
|
135
|
-
padding: '0.45rem 0.6rem',
|
|
136
|
-
width: '100%',
|
|
137
|
-
}, type: "search", value: query }), _jsx("div", { style: {
|
|
138
|
-
display: 'grid',
|
|
139
|
-
gap: 4,
|
|
140
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${CELL}px, 1fr))`,
|
|
141
|
-
maxHeight: 260,
|
|
142
|
-
overflowY: 'auto',
|
|
143
|
-
paddingBottom: 4,
|
|
144
|
-
}, children: filtered.map(({ name, Icon }) => {
|
|
145
|
-
const isActive = name === selected;
|
|
146
|
-
return (_jsx("button", { onClick: () => pick(name), style: {
|
|
147
|
-
alignItems: 'center',
|
|
148
|
-
aspectRatio: '1',
|
|
149
|
-
background: isActive
|
|
150
|
-
? 'var(--theme-success-100, var(--theme-elevation-100))'
|
|
151
|
-
: 'transparent',
|
|
152
|
-
border: isActive
|
|
153
|
-
? '1px solid var(--theme-success-500, var(--theme-elevation-400))'
|
|
154
|
-
: '1px solid transparent',
|
|
155
|
-
borderRadius: 6,
|
|
156
|
-
color: 'var(--theme-text)',
|
|
157
|
-
cursor: 'pointer',
|
|
158
|
-
display: 'inline-flex',
|
|
159
|
-
justifyContent: 'center',
|
|
160
|
-
padding: 0,
|
|
161
|
-
}, title: name, type: "button", children: _jsx(Icon, { size: 18 }) }, name));
|
|
162
|
-
}) }), _jsx("div", { style: {
|
|
163
|
-
color: 'var(--theme-elevation-500)',
|
|
164
|
-
fontSize: 11,
|
|
165
|
-
marginTop: 6,
|
|
166
|
-
}, children: totalMatches === 0
|
|
167
|
-
? 'No icons match.'
|
|
168
|
-
: totalMatches > MAX_VISIBLE
|
|
169
|
-
? `Showing ${MAX_VISIBLE} of ${totalMatches} — refine search`
|
|
170
|
-
: `${totalMatches} icon${totalMatches === 1 ? '' : 's'}` })] })) : null] }), _jsx(FieldDescription, { description: field?.admin?.description, path: path }), _jsx(FieldError, { message: errorMessage, path: path, showError: showError })] }));
|
|
95
|
+
const triggerLabel = selected ?? t(achievementsKey('chooseIcon'));
|
|
96
|
+
const triggerIcon = SelectedIcon ? _jsx(SelectedIcon, { size: 18 }) : undefined;
|
|
97
|
+
return (_jsxs("div", { className: "field-type", children: [_jsx(FieldLabel, { label: field?.label ?? t(achievementsKey('icon')), path: path, required: Boolean(field?.required) }), _jsxs("div", { style: { alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '0.5rem' }, children: [readOnly ? (_jsx(Button, { buttonStyle: "secondary", disabled: true, icon: triggerIcon, iconPosition: "left", size: "medium", type: "button", children: triggerLabel })) : (_jsx(Popup, { buttonType: "custom", onToggleOpen: (active) => {
|
|
98
|
+
setOpen(active);
|
|
99
|
+
if (!active)
|
|
100
|
+
setQuery('');
|
|
101
|
+
}, popupAriaLabel: t(achievementsKey('searchLucideIcons')), renderButton: (buttonProps) => (_jsx(Button, { "aria-expanded": buttonProps['aria-expanded'], "aria-haspopup": buttonProps['aria-haspopup'], buttonStyle: "secondary", icon: triggerIcon, iconPosition: "left", onClick: buttonProps.onClick, onKeyDown: buttonProps.onKeyDown, size: "medium", type: "button", children: triggerLabel })), size: "fit-content", theme: "auto", verticalAlign: "bottom", children: _jsxs("div", { style: pickerPanelStyle, children: [_jsx(TextInput, { htmlAttributes: {
|
|
102
|
+
'aria-label': t(achievementsKey('searchLucideIcons')),
|
|
103
|
+
}, inputRef: searchRef, onChange: (event) => setQuery(event.target.value), path: `${path}__lucideSearch`, placeholder: t(achievementsKey('searchIcons')), size: "medium", value: query }), _jsx("div", { style: iconGridStyle, children: filtered.map(({ name, Icon }) => {
|
|
104
|
+
const isActive = name === selected;
|
|
105
|
+
return (_jsx("button", { onClick: () => pick(name), style: {
|
|
106
|
+
alignItems: 'center',
|
|
107
|
+
aspectRatio: '1',
|
|
108
|
+
background: isActive ? 'var(--color-bg-selected)' : 'transparent',
|
|
109
|
+
border: isActive
|
|
110
|
+
? '1px solid var(--color-border-selected)'
|
|
111
|
+
: '1px solid transparent',
|
|
112
|
+
borderRadius: 'var(--radius-medium)',
|
|
113
|
+
color: 'var(--color-text)',
|
|
114
|
+
cursor: 'pointer',
|
|
115
|
+
display: 'inline-flex',
|
|
116
|
+
justifyContent: 'center',
|
|
117
|
+
padding: 0,
|
|
118
|
+
}, title: name, type: "button", children: _jsx(Icon, { size: 18 }) }, name));
|
|
119
|
+
}) }), _jsx("div", { style: footerStyle, children: totalMatches === 0
|
|
120
|
+
? t(achievementsKey('noIconsMatch'))
|
|
121
|
+
: totalMatches > MAX_VISIBLE
|
|
122
|
+
? t(achievementsKey('showingIcons'), { shown: MAX_VISIBLE, total: totalMatches })
|
|
123
|
+
: t(achievementsKey('iconCount'), { count: totalMatches }) })] }) })), selected && !readOnly ? (_jsx(Button, { buttonStyle: "ghost", onClick: clear, size: "medium", type: "button", children: t(achievementsKey('clear')) })) : null] }), _jsx(FieldDescription, { description: field?.admin?.description, path: path }), _jsx(FieldError, { message: errorMessage, path: path, showError: showError })] }));
|
|
171
124
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
type ReconcileProgressionButtonProps = {
|
|
3
|
-
/**
|
|
3
|
+
/** Plugin endpoint path (no `/api` prefix), e.g. `/achievements/reconcile`. */
|
|
4
4
|
reconcilePath: string;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReconcileProgressionButton.d.ts","sourceRoot":"","sources":["../../src/admin/ReconcileProgressionButton.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ReconcileProgressionButton.d.ts","sourceRoot":"","sources":["../../src/admin/ReconcileProgressionButton.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAgC,MAAM,OAAO,CAAA;AAKpD,KAAK,+BAA+B,GAAG;IACrC,+EAA+E;IAC/E,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,qBAiEhF"}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Button, toast, useConfig } from '@payloadcms/ui';
|
|
4
|
+
import { formatAdminURL } from 'payload/shared';
|
|
4
5
|
import { useCallback, useState } from 'react';
|
|
6
|
+
import { achievementsKey } from '../translations/keys.js';
|
|
7
|
+
import { usePluginT } from './usePluginT.js';
|
|
5
8
|
/**
|
|
6
9
|
* Grants list control — runs progression reconcile for all users with grants.
|
|
7
10
|
*/
|
|
8
11
|
export function ReconcileProgressionButton(props) {
|
|
9
12
|
const { reconcilePath } = props;
|
|
10
13
|
const { config } = useConfig();
|
|
14
|
+
const t = usePluginT();
|
|
11
15
|
const [busy, setBusy] = useState(false);
|
|
12
16
|
const onClick = useCallback(async () => {
|
|
13
17
|
if (busy)
|
|
14
18
|
return;
|
|
15
19
|
setBusy(true);
|
|
16
20
|
try {
|
|
17
|
-
const
|
|
18
|
-
const url =
|
|
21
|
+
const path = (reconcilePath.startsWith('/') ? reconcilePath : `/${reconcilePath}`);
|
|
22
|
+
const url = formatAdminURL({
|
|
23
|
+
apiRoute: config.routes?.api ?? '/api',
|
|
24
|
+
path,
|
|
25
|
+
serverURL: config.serverURL,
|
|
26
|
+
});
|
|
19
27
|
const res = await fetch(url, {
|
|
20
28
|
method: 'POST',
|
|
21
29
|
credentials: 'include',
|
|
@@ -24,18 +32,24 @@ export function ReconcileProgressionButton(props) {
|
|
|
24
32
|
});
|
|
25
33
|
const json = (await res.json().catch(() => null));
|
|
26
34
|
if (!res.ok) {
|
|
27
|
-
const message = json?.errors?.[0]?.message ??
|
|
35
|
+
const message = json?.errors?.[0]?.message ?? t(achievementsKey('requestFailedStatus'), { status: res.status });
|
|
28
36
|
toast.error(message);
|
|
29
37
|
return;
|
|
30
38
|
}
|
|
31
|
-
toast.success(
|
|
39
|
+
toast.success(t(achievementsKey('repairComplete'), {
|
|
40
|
+
users: json?.usersScanned ?? 0,
|
|
41
|
+
grants: json?.compositesGranted ?? 0,
|
|
42
|
+
logs: json?.grantedLogsBackfilled ?? 0,
|
|
43
|
+
requests: json?.achievementRequestsEnsured ?? 0,
|
|
44
|
+
tierRequests: json?.tierRequestsEnsured ?? 0,
|
|
45
|
+
}));
|
|
32
46
|
}
|
|
33
47
|
catch (error) {
|
|
34
|
-
toast.error(error instanceof Error ? error.message : '
|
|
48
|
+
toast.error(error instanceof Error ? error.message : t(achievementsKey('repairFailed')));
|
|
35
49
|
}
|
|
36
50
|
finally {
|
|
37
51
|
setBusy(false);
|
|
38
52
|
}
|
|
39
|
-
}, [busy, config.serverURL, reconcilePath]);
|
|
40
|
-
return (_jsx("div", { style: { marginBottom: '1rem' }, children: _jsx(Button, { buttonStyle: "secondary", disabled: busy, onClick: () => void onClick(), children: busy ? '
|
|
53
|
+
}, [busy, config.routes?.api, config.serverURL, reconcilePath, t]);
|
|
54
|
+
return (_jsx("div", { style: { marginBottom: '1rem' }, children: _jsx(Button, { buttonStyle: "secondary", disabled: busy, onClick: () => void onClick(), children: t(achievementsKey(busy ? 'repairing' : 'repairProgression')) }) }));
|
|
41
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEventTypeFlags.d.ts","sourceRoot":"","sources":["../../src/admin/useEventTypeFlags.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEventTypeFlags.d.ts","sourceRoot":"","sources":["../../src/admin/useEventTypeFlags.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,OAAO,CAAA;IACtB,cAAc,EAAE,OAAO,CAAA;IACvB,eAAe,EAAE,OAAO,CAAA;IACxB,iBAAiB,EAAE,MAAM,EAAE,CAAA;CAC5B,CAAA;AAqDD,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,cAAc,CA8CxE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useConfig, useFormFields } from '@payloadcms/ui';
|
|
3
|
+
import { formatAdminURL } from 'payload/shared';
|
|
3
4
|
import { useEffect, useMemo, useState } from 'react';
|
|
4
5
|
function relationId(value) {
|
|
5
6
|
if (typeof value === 'string' && value)
|
|
@@ -61,11 +62,13 @@ export function useEventTypeFlags(eventTypesSlug) {
|
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
64
|
const controller = new AbortController();
|
|
64
|
-
const
|
|
65
|
-
const serverURL = config.serverURL ?? '';
|
|
66
|
-
const url = `${serverURL}${api}/${eventTypesSlug}/${typeId}` +
|
|
67
|
-
`?depth=0&select[requiresActor]=true&select[requiresMetric]=true` +
|
|
65
|
+
const query = `?depth=0&select[requiresActor]=true&select[requiresMetric]=true` +
|
|
68
66
|
`&select[requiresSubject]=true&select[subjectRelationTo]=true&select[slug]=true`;
|
|
67
|
+
const url = formatAdminURL({
|
|
68
|
+
apiRoute: config.routes?.api ?? '/api',
|
|
69
|
+
path: `/${eventTypesSlug}/${typeId}${query}`,
|
|
70
|
+
serverURL: config.serverURL,
|
|
71
|
+
});
|
|
69
72
|
void fetch(url, { credentials: 'include', signal: controller.signal })
|
|
70
73
|
.then(async (res) => {
|
|
71
74
|
if (!res.ok) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin `t` widened for plugin keys (`plugin-achievements:…`).
|
|
3
|
+
* Host DefaultTranslationKeys don’t include plugin namespaces until merged at runtime.
|
|
4
|
+
*/
|
|
5
|
+
export declare function usePluginT(): (key: string, vars?: Record<string, unknown>) => string;
|
|
6
|
+
//# sourceMappingURL=usePluginT.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePluginT.d.ts","sourceRoot":"","sources":["../../src/admin/usePluginT.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,UAAU,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAGpF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useTranslation } from '@payloadcms/ui';
|
|
3
|
+
/**
|
|
4
|
+
* Admin `t` widened for plugin keys (`plugin-achievements:…`).
|
|
5
|
+
* Host DefaultTranslationKeys don’t include plugin namespaces until merged at runtime.
|
|
6
|
+
*/
|
|
7
|
+
export function usePluginT() {
|
|
8
|
+
const { t } = useTranslation();
|
|
9
|
+
return t;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DescriptionFunction, EntityDescriptionFunction, LabelFunction } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Admin label via merged plugin translations: `t('plugin-achievements:…')`.
|
|
4
|
+
* Matches Form Builder / PLUGIN-DEVELOPMENT (merge `translations`, resolve with `t`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function tLabel(key: string): LabelFunction;
|
|
7
|
+
/** Field `admin.description` via plugin `t`. */
|
|
8
|
+
export declare function tDescription(key: string): DescriptionFunction;
|
|
9
|
+
/** Collection / global `admin.description` via plugin `t`. */
|
|
10
|
+
export declare function tEntityDescription(key: string): EntityDescriptionFunction;
|
|
11
|
+
/** Host `custom:…` keys when the host owns the string catalog. */
|
|
12
|
+
export declare function adminLabel(key: string): LabelFunction;
|
|
13
|
+
/** Field `admin.description` via host `t`. */
|
|
14
|
+
export declare function adminDescription(key: string): DescriptionFunction;
|
|
15
|
+
/** Collection / global `admin.description` via host `t`. */
|
|
16
|
+
export declare function adminEntityDescription(key: string): EntityDescriptionFunction;
|
|
17
|
+
//# sourceMappingURL=adminLabel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adminLabel.d.ts","sourceRoot":"","sources":["../src/adminLabel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAM5F;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAEjD;AAED,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAE7D;AAED,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,yBAAyB,CAEzE;AAED,kEAAkE;AAClE,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAErD;AAED,8CAA8C;AAC9C,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAEjE;AAED,4DAA4D;AAC5D,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,yBAAyB,CAE7E"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { achievementsKey } from './translations/keys.js';
|
|
2
|
+
/**
|
|
3
|
+
* Admin label via merged plugin translations: `t('plugin-achievements:…')`.
|
|
4
|
+
* Matches Form Builder / PLUGIN-DEVELOPMENT (merge `translations`, resolve with `t`).
|
|
5
|
+
*/
|
|
6
|
+
export function tLabel(key) {
|
|
7
|
+
return ({ t }) => t(achievementsKey(key));
|
|
8
|
+
}
|
|
9
|
+
/** Field `admin.description` via plugin `t`. */
|
|
10
|
+
export function tDescription(key) {
|
|
11
|
+
return ({ t }) => t(achievementsKey(key));
|
|
12
|
+
}
|
|
13
|
+
/** Collection / global `admin.description` via plugin `t`. */
|
|
14
|
+
export function tEntityDescription(key) {
|
|
15
|
+
return ({ t }) => t(achievementsKey(key));
|
|
16
|
+
}
|
|
17
|
+
/** Host `custom:…` keys when the host owns the string catalog. */
|
|
18
|
+
export function adminLabel(key) {
|
|
19
|
+
return ({ t }) => t(key);
|
|
20
|
+
}
|
|
21
|
+
/** Field `admin.description` via host `t`. */
|
|
22
|
+
export function adminDescription(key) {
|
|
23
|
+
return ({ t }) => t(key);
|
|
24
|
+
}
|
|
25
|
+
/** Collection / global `admin.description` via host `t`. */
|
|
26
|
+
export function adminEntityDescription(key) {
|
|
27
|
+
return ({ t }) => t(key);
|
|
28
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareAchievementRequest.d.ts","sourceRoot":"","sources":["../../../../src/collections/AchievementRequests/hooks/prepareAchievementRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,4BAA4B,EAE7B,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"prepareAchievementRequest.d.ts","sourceRoot":"","sources":["../../../../src/collections/AchievementRequests/hooks/prepareAchievementRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,4BAA4B,EAE7B,MAAM,SAAS,CAAA;AA4ChB;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,4BAkEvC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,yBAsCpC,CAAA"}
|
|
@@ -4,6 +4,7 @@ import { CTX_SYSTEM_REQUEST } from '../../../services/achievement/contextFlags.j
|
|
|
4
4
|
import { evaluateRules, ruleGroupHasProgressRequirements } from '../../../services/achievement/evaluateRules.js';
|
|
5
5
|
import { grantAchievement } from '../../../services/achievement/submitAchievementRequest.js';
|
|
6
6
|
import { relationId } from '../../../services/achievement/relationId.js';
|
|
7
|
+
import { throwApiError } from '../../../translations/reqT.js';
|
|
7
8
|
function scopeIdOf(data) {
|
|
8
9
|
const scope = data?.scope;
|
|
9
10
|
if (!scope)
|
|
@@ -13,7 +14,7 @@ function scopeIdOf(data) {
|
|
|
13
14
|
async function resolveAchievement(args) {
|
|
14
15
|
const achievementId = relationId(args.data.achievement);
|
|
15
16
|
if (!achievementId) {
|
|
16
|
-
|
|
17
|
+
throwApiError(args.req, 'errorAchievementRequired', 400);
|
|
17
18
|
}
|
|
18
19
|
const doc = (await args.req.payload.findByID({
|
|
19
20
|
collection: collectionOf('achievements'),
|
|
@@ -23,7 +24,7 @@ async function resolveAchievement(args) {
|
|
|
23
24
|
req: args.req,
|
|
24
25
|
}));
|
|
25
26
|
if (!doc)
|
|
26
|
-
|
|
27
|
+
throwApiError(args.req, 'errorUnknownAchievement', 400, { id: achievementId });
|
|
27
28
|
return doc;
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
@@ -45,12 +46,12 @@ export const prepareAchievementRequest = async ({ data, operation, req, original
|
|
|
45
46
|
else {
|
|
46
47
|
const bound = relationId(data.user);
|
|
47
48
|
if (!bound)
|
|
48
|
-
|
|
49
|
+
throwApiError(req, 'errorUserRequired', 400);
|
|
49
50
|
data.user = bound;
|
|
50
51
|
}
|
|
51
52
|
const userId = relationId(data.user);
|
|
52
53
|
if (!userId)
|
|
53
|
-
|
|
54
|
+
throwApiError(req, 'errorUserRequired', 400);
|
|
54
55
|
const scopeId = scopeIdOf(data);
|
|
55
56
|
const achievement = await resolveAchievement({
|
|
56
57
|
req,
|
|
@@ -58,7 +59,7 @@ export const prepareAchievementRequest = async ({ data, operation, req, original
|
|
|
58
59
|
});
|
|
59
60
|
data.achievement = achievement.id;
|
|
60
61
|
if (!system && ruleGroupHasProgressRequirements(achievement.completionRules)) {
|
|
61
|
-
|
|
62
|
+
throwApiError(req, 'errorGrantedAutomatically', 400);
|
|
62
63
|
}
|
|
63
64
|
if (!system) {
|
|
64
65
|
const eligible = await evaluateRules({
|
|
@@ -69,7 +70,7 @@ export const prepareAchievementRequest = async ({ data, operation, req, original
|
|
|
69
70
|
scopeId,
|
|
70
71
|
});
|
|
71
72
|
if (!eligible) {
|
|
72
|
-
|
|
73
|
+
throwApiError(req, 'errorEligibilityRulesNotMet', 400);
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
if (system) {
|
|
@@ -104,7 +105,7 @@ export const grantOnApprovedRequest = async ({ doc, operation, previousDoc, req,
|
|
|
104
105
|
const achievementId = relationId(doc.achievement);
|
|
105
106
|
const userId = relationId(doc.user);
|
|
106
107
|
if (!achievementId || !userId) {
|
|
107
|
-
|
|
108
|
+
throwApiError(req, 'errorApprovedRequestIncomplete', 400);
|
|
108
109
|
}
|
|
109
110
|
const scopeId = scopeIdOf(doc);
|
|
110
111
|
const note = doc.note;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/AchievementRequests/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/AchievementRequests/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAQtD,wBAAgB,kCAAkC,IAAI,gBAAgB,CA+CrE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tEntityDescription, tLabel } from '../../adminLabel.js';
|
|
1
2
|
import { collectionAdmin, collectionOf, optionalFields, slugOf } from '../helpers.js';
|
|
2
3
|
import { scopeField, userField } from '../fields/index.js';
|
|
3
4
|
import { access } from './access/index.js';
|
|
@@ -5,12 +6,16 @@ import { hooks } from './hooks/index.js';
|
|
|
5
6
|
export function buildAchievementRequestsCollection() {
|
|
6
7
|
return {
|
|
7
8
|
slug: slugOf('achievementRequests'),
|
|
9
|
+
labels: {
|
|
10
|
+
singular: tLabel('achievementRequest'),
|
|
11
|
+
plural: tLabel('achievementRequests'),
|
|
12
|
+
},
|
|
8
13
|
access: { ...access },
|
|
9
14
|
hooks,
|
|
10
15
|
admin: collectionAdmin({
|
|
11
16
|
useAsTitle: 'id',
|
|
12
17
|
defaultColumns: ['user', 'achievement', 'status', 'createdAt'],
|
|
13
|
-
description: '
|
|
18
|
+
description: tEntityDescription('whenSomeoneAsksToEarnAnAchievementWe'),
|
|
14
19
|
}),
|
|
15
20
|
fields: [
|
|
16
21
|
...optionalFields(scopeField()),
|
|
@@ -21,19 +26,28 @@ export function buildAchievementRequestsCollection() {
|
|
|
21
26
|
relationTo: collectionOf('achievements'),
|
|
22
27
|
required: true,
|
|
23
28
|
index: true,
|
|
29
|
+
label: tLabel('achievement'),
|
|
24
30
|
},
|
|
25
31
|
{
|
|
26
32
|
name: 'status',
|
|
27
33
|
type: 'select',
|
|
28
34
|
required: true,
|
|
29
35
|
defaultValue: 'pending',
|
|
36
|
+
label: tLabel('status'),
|
|
30
37
|
options: [
|
|
31
|
-
{ label: '
|
|
32
|
-
{ label: '
|
|
33
|
-
{ label: '
|
|
38
|
+
{ label: tLabel('pending'), value: 'pending' },
|
|
39
|
+
{ label: tLabel('approved'), value: 'approved' },
|
|
40
|
+
{ label: tLabel('rejected'), value: 'rejected' },
|
|
34
41
|
],
|
|
35
42
|
},
|
|
36
|
-
{
|
|
43
|
+
{
|
|
44
|
+
name: 'note',
|
|
45
|
+
type: 'textarea',
|
|
46
|
+
label: tLabel('note'),
|
|
47
|
+
admin: {
|
|
48
|
+
description: tLabel('optionalNoteFromTheRequesterOrReviewer'),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
37
51
|
],
|
|
38
52
|
};
|
|
39
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/Achievements/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/Achievements/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAQ/C,wBAAgB,2BAA2B,IAAI,gBAAgB,CAmF9D"}
|