- TODO(#58) implement some kind of user landing page.
+const pactaClient = usePACTA()
+const { fromParams } = useURLParams()
+const { loading: { withLoading }, permissionDenied: { setPermissionDenied } } = useModal()
+const router = useRouter()
+const localePath = useLocalePath()
+const i18n = useI18n()
+const { getMaybeMe } = useSession()
+
+const id = presentOrCheckURL(fromParams('id'))
+const prefix = `user/[${id}]`
- For admins/the user themselves, this is where their portfolio library would go.
+const { isAdmin, maybeMe } = await getMaybeMe()
+const { data } = await useSimpleAsyncData(`${prefix}.getUser`, () => pactaClient.findUserById(id))
+const {
+ editorValues,
+ editorFields,
+ changes,
+ saveTooltip,
+ canSave,
+} = userEditor(presentOrCheckURL(data.value, 'no user in response'), i18n)
- For other users looking at this it's probably a 404, or just very rudimentary data about a user
+const deleteUser = () => withLoading(
+ () => pactaClient.deleteUser(id).then(() => router.push(localePath('/'))),
+ `${prefix}.deleteUser`,
+)
+const saveChanges = () => withLoading(
+ () => pactaClient.updateUser(id, changes.value)
+ .then(() => router.push(localePath(`/user/${id}`))),
+ `${prefix}.saveChanges`,
+)
+const isMe = computed
(() => {
+ const mm = maybeMe.value
+ return !!mm && id === mm.id
+})
+if (!isMe.value && !isAdmin.value) {
+ setPermissionDenied(new Error(`permission denied for user ${id}`))
+}
+
+
+
+