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 React from 'react';
|
||||||
import { defineMessages, useIntl } from 'react-intl';
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
|
|
||||||
|
import { patchMe } from 'soapbox/actions/me';
|
||||||
import List, { ListItem } from 'soapbox/components/list';
|
import List, { ListItem } from 'soapbox/components/list';
|
||||||
import { Button, Column, HStack, Icon, Input } from 'soapbox/components/ui';
|
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 {
|
interface IEditIdentity {
|
||||||
}
|
}
|
||||||
|
@ -11,6 +13,8 @@ interface IEditIdentity {
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
title: { id: 'settings.edit_identity', defaultMessage: 'Identity' },
|
title: { id: 'settings.edit_identity', defaultMessage: 'Identity' },
|
||||||
username: { id: 'edit_profile.fields.nip05_label', defaultMessage: 'Username' },
|
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 = [
|
const identifiers = [
|
||||||
|
@ -22,10 +26,20 @@ const identifiers = [
|
||||||
/** EditIdentity component. */
|
/** EditIdentity component. */
|
||||||
const EditIdentity: React.FC<IEditIdentity> = () => {
|
const EditIdentity: React.FC<IEditIdentity> = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
const { account } = useOwnAccount();
|
const { account } = useOwnAccount();
|
||||||
|
|
||||||
if (!account) return null;
|
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 (
|
return (
|
||||||
<Column label={intl.formatMessage(messages.title)}>
|
<Column label={intl.formatMessage(messages.title)}>
|
||||||
<List>
|
<List>
|
||||||
|
@ -33,8 +47,8 @@ const EditIdentity: React.FC<IEditIdentity> = () => {
|
||||||
<ListItem
|
<ListItem
|
||||||
key={identifier}
|
key={identifier}
|
||||||
label={identifier}
|
label={identifier}
|
||||||
isSelected={account.acct === identifier}
|
isSelected={account.source?.nostr?.nip05 === identifier}
|
||||||
onSelect={() => { /* TODO */ }}
|
onSelect={() => updateNip05(identifier)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<ListItem label={<UsernameInput />}>
|
<ListItem label={<UsernameInput />}>
|
||||||
|
|
Loading…
Reference in a new issue