EditIdentity: save nip05 to profile
This commit is contained in:
parent
fb3af2f74b
commit
51978c83f0
1 changed files with 17 additions and 3 deletions
|
@ -1,9 +1,11 @@
|
|||
import React from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import { patchMe } from 'soapbox/actions/me';
|
||||
import List, { ListItem } from 'soapbox/components/list';
|
||||
import { Button, Column, HStack, Icon, Input } from 'soapbox/components/ui';
|
||||
import { useInstance, useOwnAccount } from 'soapbox/hooks';
|
||||
import { useAppDispatch, useInstance, useOwnAccount } from 'soapbox/hooks';
|
||||
import toast from 'soapbox/toast';
|
||||
|
||||
interface IEditIdentity {
|
||||
}
|
||||
|
@ -11,6 +13,8 @@ interface IEditIdentity {
|
|||
const messages = defineMessages({
|
||||
title: { id: 'settings.edit_identity', defaultMessage: 'Identity' },
|
||||
username: { id: 'edit_profile.fields.nip05_label', defaultMessage: 'Username' },
|
||||
success: { id: 'edit_profile.success', defaultMessage: 'Your profile has been successfully saved!' },
|
||||
error: { id: 'edit_profile.error', defaultMessage: 'Profile update failed' },
|
||||
});
|
||||
|
||||
const identifiers = [
|
||||
|
@ -22,10 +26,20 @@ const identifiers = [
|
|||
/** EditIdentity component. */
|
||||
const EditIdentity: React.FC<IEditIdentity> = () => {
|
||||
const intl = useIntl();
|
||||
const dispatch = useAppDispatch();
|
||||
const { account } = useOwnAccount();
|
||||
|
||||
if (!account) return null;
|
||||
|
||||
const updateNip05 = async (nip05: string): Promise<void> => {
|
||||
try {
|
||||
await dispatch(patchMe({ nip05 }));
|
||||
toast.success(intl.formatMessage(messages.success));
|
||||
} catch (e) {
|
||||
toast.error(intl.formatMessage(messages.error));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Column label={intl.formatMessage(messages.title)}>
|
||||
<List>
|
||||
|
@ -33,8 +47,8 @@ const EditIdentity: React.FC<IEditIdentity> = () => {
|
|||
<ListItem
|
||||
key={identifier}
|
||||
label={identifier}
|
||||
isSelected={account.acct === identifier}
|
||||
onSelect={() => { /* TODO */ }}
|
||||
isSelected={account.source?.nostr?.nip05 === identifier}
|
||||
onSelect={() => updateNip05(identifier)}
|
||||
/>
|
||||
))}
|
||||
<ListItem label={<UsernameInput />}>
|
||||
|
|
Loading…
Reference in a new issue