Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move the 404 redirect to the router
  • Loading branch information
m1r0 committed Aug 19, 2025
commit 1755dbba9cbf2defa34fcb954eefb4a511575cdc
16 changes: 15 additions & 1 deletion client/dashboard/app/router/domains.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRoute, createLazyRoute, redirect } from '@tanstack/react-router';
import { createRoute, createLazyRoute, notFound, redirect } from '@tanstack/react-router';
import { domainQuery } from '../queries/domain';
import { domainDnsQuery } from '../queries/domain-dns-records';
import { domainForwardingQuery } from '../queries/domain-forwarding';
Expand Down Expand Up @@ -189,6 +189,20 @@ export const domainGlueRecordsAddRoute = createRoute( {
export const domainGlueRecordsEditRoute = createRoute( {
getParentRoute: () => domainRoute,
path: 'glue-records/edit/$nameServer',
beforeLoad: async ( { params: { domainName, nameServer } } ) => {
const glueRecordsData = await queryClient.ensureQueryData(
domainGlueRecordsQuery( domainName )
);
const glueRecord = glueRecordsData.find(
( glueRecord ) => glueRecord.nameserver === nameServer
);

if ( ! glueRecord ) {
throw notFound();
}
},
loader: ( { params: { domainName } } ) =>
queryClient.ensureQueryData( domainGlueRecordsQuery( domainName ) ),
} ).lazy( () =>
import( '../../domains/overview-glue-records/edit' ).then( ( d ) =>
createLazyRoute( 'domain-glue-records-edit' )( {
Expand Down
26 changes: 7 additions & 19 deletions client/dashboard/domains/overview-glue-records/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useSuspenseQuery, useMutation } from '@tanstack/react-query';
import { notFound, useNavigate } from '@tanstack/react-router';
import { useNavigate } from '@tanstack/react-router';
import { useDispatch } from '@wordpress/data';
import { useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import {
Expand All @@ -11,6 +10,7 @@ import {
import { domainRoute, domainGlueRecordsRoute } from '../../app/router';
import { PageHeader } from '../../components/page-header';
import PageLayout from '../../components/page-layout';
import { DomainGlueRecord } from '../../data/domain-glue-records';
import DomainGlueRecordsForm from './form';
import type { FormData } from './form';

Expand All @@ -20,24 +20,12 @@ export default function EditDomainGlueRecords() {
const { data: glueRecordsData } = useSuspenseQuery( domainGlueRecordsQuery( domainName ) );
const updateMutation = useMutation( domainGlueRecordUpdateMutation( domainName ) );
const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore );

const existingGlueRecord = useMemo( () => {
if ( ! glueRecordsData || ! nameServer ) {
throw notFound();
}
const existingGlueRecord = glueRecordsData.find( ( f ) => f.nameserver === nameServer );
if ( ! existingGlueRecord ) {
throw notFound();
}
return existingGlueRecord;
}, [ glueRecordsData, nameServer ] );
const glueRecord = glueRecordsData.find(
( glueRecord: DomainGlueRecord ) => glueRecord.nameserver === nameServer
);

const handleSubmit = ( formData: FormData ) => {
if ( ! existingGlueRecord ) {
return;
}

const updatedGlueRecord = {
const updatedGlueRecord: DomainGlueRecord = {
nameserver: formData.nameServer,
ip_addresses: [ formData.ipAddress ],
};
Expand All @@ -62,7 +50,7 @@ export default function EditDomainGlueRecords() {
<PageLayout size="small" header={ <PageHeader title={ __( 'Edit glue record' ) } /> }>
<DomainGlueRecordsForm
domainName={ domainName }
initialData={ existingGlueRecord }
initialData={ glueRecord }
onSubmit={ handleSubmit }
isSubmitting={ updateMutation.isPending }
isEdit
Expand Down