allow undo delete
This commit is contained in:
@@ -88,23 +88,56 @@ function GermSelfButton({did}: {did: string}) {
|
|||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
const {mutate, isPending} = useMutation({
|
const {mutate: deleteDeclaration, isPending} = useMutation({
|
||||||
onMutate: async () => {
|
onMutate: async () => {
|
||||||
|
const previousRecord = await agent.com.germnetwork.declaration
|
||||||
|
.get({
|
||||||
|
repo: did,
|
||||||
|
rkey: 'self',
|
||||||
|
})
|
||||||
|
.then(res => res.value)
|
||||||
|
.catch(() => null)
|
||||||
|
|
||||||
await agent.com.germnetwork.declaration.delete({
|
await agent.com.germnetwork.declaration.delete({
|
||||||
repo: did,
|
repo: did,
|
||||||
rkey: 'self',
|
rkey: 'self',
|
||||||
})
|
})
|
||||||
|
|
||||||
await whenAppViewReady(agent, did, res => !res.data.associated?.germ)
|
await whenAppViewReady(agent, did, res => !res.data.associated?.germ)
|
||||||
|
|
||||||
|
return previousRecord
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: (_data, _variables, previousRecord) => {
|
||||||
selfExplanationDialogControl.close(() => {
|
async function undo() {
|
||||||
Toast.show(
|
if (!previousRecord) return
|
||||||
_(
|
await agent.com.germnetwork.declaration.put(
|
||||||
msg`Germ DM link disconnected. You can reconnect it at any time through the Germ app.`,
|
{
|
||||||
),
|
repo: did,
|
||||||
|
rkey: 'self',
|
||||||
|
},
|
||||||
|
previousRecord,
|
||||||
)
|
)
|
||||||
|
await whenAppViewReady(agent, did, res => !!res.data.associated?.germ)
|
||||||
|
await queryClient.refetchQueries({queryKey: RQKEY(did)})
|
||||||
|
|
||||||
|
Toast.show(_(msg`Germ DM reconnected`))
|
||||||
|
}
|
||||||
|
|
||||||
|
selfExplanationDialogControl.close(() => {
|
||||||
void queryClient.refetchQueries({queryKey: RQKEY(did)})
|
void queryClient.refetchQueries({queryKey: RQKEY(did)})
|
||||||
|
Toast.show(
|
||||||
|
<Toast.Outer>
|
||||||
|
<Toast.Icon />
|
||||||
|
<Toast.Text>
|
||||||
|
<Trans>Germ DM disconnected</Trans>
|
||||||
|
</Toast.Text>
|
||||||
|
{previousRecord && (
|
||||||
|
<Toast.Action label={_(msg`Undo`)} onPress={() => void undo()}>
|
||||||
|
<Trans>Undo</Trans>
|
||||||
|
</Toast.Action>
|
||||||
|
)}
|
||||||
|
</Toast.Outer>,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onError: error => {
|
onError: error => {
|
||||||
@@ -154,21 +187,21 @@ function GermSelfButton({did}: {did: string}) {
|
|||||||
can manage its visibility from the Germ DM app.
|
can manage its visibility from the Germ DM app.
|
||||||
</Trans>
|
</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[a.mt_2xl]}>
|
<View style={[a.mt_2xl, a.gap_md]}>
|
||||||
<Button
|
<Button
|
||||||
label={_(msg``)}
|
label={_(msg`Got it`)}
|
||||||
size="large"
|
size="large"
|
||||||
color="primary"
|
color="primary"
|
||||||
onPress={() => selfExplanationDialogControl.close()}>
|
onPress={() => selfExplanationDialogControl.close()}>
|
||||||
<ButtonText>
|
<ButtonText>
|
||||||
<Trans>Got it!</Trans>
|
<Trans>Got it</Trans>
|
||||||
</ButtonText>
|
</ButtonText>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
label={_(msg`Disconnect Germ DM`)}
|
label={_(msg`Disconnect Germ DM`)}
|
||||||
size="large"
|
size="large"
|
||||||
color="primary"
|
color="secondary"
|
||||||
onPress={() => mutate()}
|
onPress={() => deleteDeclaration()}
|
||||||
disabled={isPending}>
|
disabled={isPending}>
|
||||||
{isPending && <ButtonIcon icon={Loader} />}
|
{isPending && <ButtonIcon icon={Loader} />}
|
||||||
<ButtonText>
|
<ButtonText>
|
||||||
|
|||||||
Reference in New Issue
Block a user