From 51978c83f089813f45f5a9a48f9e547a862fd5b1 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 25 Mar 2024 12:43:36 -0500 Subject: [PATCH] EditIdentity: save nip05 to profile --- src/features/edit-identity/index.tsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/features/edit-identity/index.tsx b/src/features/edit-identity/index.tsx index 0b26631d2..8efcdd1fd 100644 --- a/src/features/edit-identity/index.tsx +++ b/src/features/edit-identity/index.tsx @@ -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 = () => { const intl = useIntl(); + const dispatch = useAppDispatch(); const { account } = useOwnAccount(); if (!account) return null; + const updateNip05 = async (nip05: string): Promise => { + try { + await dispatch(patchMe({ nip05 })); + toast.success(intl.formatMessage(messages.success)); + } catch (e) { + toast.error(intl.formatMessage(messages.error)); + } + }; + return ( @@ -33,8 +47,8 @@ const EditIdentity: React.FC = () => { { /* TODO */ }} + isSelected={account.source?.nostr?.nip05 === identifier} + onSelect={() => updateNip05(identifier)} /> ))} }>