0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

fix(connector,console): should reset email sent count for new connector (#4148)

This commit is contained in:
Darcy Ye 2023-07-11 15:19:52 +08:00 committed by GitHub
parent 8d282e083f
commit b1c1e03203
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 4 deletions

View file

@ -97,7 +97,7 @@ const getUsage =
},
timeout: { request: defaultTimeout },
searchParams: {
startFrom: startFrom?.toISOString(),
from: startFrom?.toISOString(),
},
});

View file

@ -22,13 +22,20 @@ type Props = {
connectorType: Exclude<ConnectorType, ConnectorType.Social>;
className?: string;
parse: () => unknown;
updateUsage?: () => void;
};
type FormData = {
sendTo: string;
};
function ConnectorTester({ connectorFactoryId, connectorType, className, parse }: Props) {
function ConnectorTester({
connectorFactoryId,
connectorType,
className,
parse,
updateUsage,
}: Props) {
const [showTooltip, setShowTooltip] = useState(false);
const {
handleSubmit,
@ -67,6 +74,7 @@ function ConnectorTester({ connectorFactoryId, connectorType, className, parse }
};
await api.post(`api/connectors/${connectorFactoryId}/test`, { json: data }).json();
updateUsage?.();
setShowTooltip(true);
})
);

View file

@ -2,7 +2,7 @@ import { ServiceConnector } from '@logto/connector-kit';
import { ConnectorType } from '@logto/schemas';
import type { ConnectorResponse } from '@logto/schemas';
import { conditional } from '@silverhand/essentials';
import { useEffect, useMemo } from 'react';
import { useCallback, useEffect, useMemo } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { toast } from 'react-hot-toast';
import { useTranslation } from 'react-i18next';
@ -26,7 +26,7 @@ import EmailServiceConnectorForm from './EmailServiceConnectorForm';
type Props = {
isDeleted: boolean;
connectorData: ConnectorResponse;
onConnectorUpdated: (connector: ConnectorResponse) => void;
onConnectorUpdated: (connector?: ConnectorResponse) => void;
};
function ConnectorContent({ isDeleted, connectorData, onConnectorUpdated }: Props) {
@ -112,6 +112,13 @@ function ConnectorContent({ isDeleted, connectorData, onConnectorUpdated }: Prop
})
);
const updateUsage = useCallback(() => {
if (connectorData.usage === undefined) {
return;
}
onConnectorUpdated({ ...connectorData, usage: connectorData.usage + 1 });
}, [connectorData, onConnectorUpdated]);
return (
<FormProvider {...methods}>
<DetailsForm
@ -153,6 +160,7 @@ function ConnectorContent({ isDeleted, connectorData, onConnectorUpdated }: Prop
connectorFactoryId={connectorId}
connectorType={connectorType}
parse={() => configParser(watch(), formItems)}
updateUsage={updateUsage}
/>
</FormCard>
)}

View file

@ -50,6 +50,10 @@ function ConnectorDetails() {
const [isReadMeOpen, setIsReadMeOpen] = useState(false);
const [isSetupOpen, setIsSetupOpen] = useState(false);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
/**
* TODO: Can add `keepPreviousData` option to useSWR to avoid the flash on `Skeleton`
* component when manually trigger `mutate` function. This change is available in `swr@v2.0` or above.
*/
const { data, error, mutate } = useSWR<ConnectorResponse, RequestError>(
connectorId && `api/connectors/${connectorId}`
);