-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
83 additions
and
130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,86 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
import { userEditor } from '@/lib/editor' | ||
<template> | ||
<div> | ||
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<boolean>(() => { | ||
const mm = maybeMe.value | ||
return !!mm && id === mm.id | ||
}) | ||
if (!isMe.value && !isAdmin.value) { | ||
setPermissionDenied(new Error(`permission denied for user ${id}`)) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-column gap-3"> | ||
<UserEditor | ||
v-if="editorValues" | ||
v-model:editorValues="editorValues" | ||
:editor-fields="editorFields" | ||
/> | ||
<div class="flex gap-3"> | ||
<PVButton | ||
icon="pi pi-trash" | ||
class="p-button-danger" | ||
label="Delete" | ||
@click="deleteUser" | ||
/> | ||
<LinkButton | ||
label="Discard Changes" | ||
icon="pi pi-arrow-left" | ||
class="p-button-secondary p-button-outlined" | ||
:to="localePath(`/user/${id}`)" | ||
/> | ||
<div v-tooltip.bottom="saveTooltip"> | ||
<PVButton | ||
:disabled="!canSave" | ||
label="Save Changes" | ||
icon="pi pi-arrow-right" | ||
icon-pos="right" | ||
@click="saveChanges" | ||
/> | ||
</div> | ||
</div> | ||
<StandardDebug | ||
:value="editorFields" | ||
label="Editor Fields" | ||
/> | ||
<StandardDebug | ||
:value="editorValues" | ||
label="Editor Values" | ||
/> | ||
<StandardDebug | ||
:value="changes" | ||
label="Changes" | ||
/> | ||
</div> | ||
</template> |