diff --git a/src/components/dashboard/SipCredentialsCard.jsx b/src/components/dashboard/SipCredentialsCard.jsx
index 34522b6..71b1f6a 100644
--- a/src/components/dashboard/SipCredentialsCard.jsx
+++ b/src/components/dashboard/SipCredentialsCard.jsx
@@ -5,7 +5,7 @@ import { useAuth } from '@/contexts/AuthContext';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
-import { Copy, KeyRound, Server, User } from 'lucide-react';
+import { Copy, KeyRound, Server, User, Check } from 'lucide-react';
import {
AlertDialog,
AlertDialogAction,
@@ -19,7 +19,7 @@ import {
} from "@/components/ui/alert-dialog"
import { Skeleton } from '@/components/ui/skeleton';
-function CredentialRow({ icon, label, value, onCopy }) {
+function CredentialRow({ icon, label, value, onCopy, isCopied }) {
return (
@@ -30,16 +30,17 @@ function CredentialRow({ icon, label, value, onCopy }) {
);
}
-export function SipCredentialsCard({ details, loading }) {
+export function SipCredentialsCard({ details, loading, refetchDetails }) {
const { token } = useAuth();
const [newSecret, setNewSecret] = useState(null);
const [isResetting, setIsResetting] = useState(false);
+ const [copiedState, setCopiedState] = useState({});
const handleResetSecret = async () => {
if (!token) return;
@@ -51,6 +52,9 @@ export function SipCredentialsCard({ details, loading }) {
});
const data = await res.json();
setNewSecret(data.newSecret);
+ if (refetchDetails) {
+ refetchDetails();
+ }
} catch (error) {
console.error("Failed to reset secret", error);
alert('Failed to reset secret.');
@@ -59,9 +63,14 @@ export function SipCredentialsCard({ details, loading }) {
}
};
- const copyToClipboard = (text) => {
- navigator.clipboard.writeText(text);
- alert('Copied to clipboard!');
+ const copyToClipboard = (text, id) => {
+ if (!text) return;
+ navigator.clipboard.writeText(text).then(() => {
+ setCopiedState(prev => ({ ...prev, [id]: true }));
+ setTimeout(() => {
+ setCopiedState(prev => ({ ...prev, [id]: false }));
+ }, 2000);
+ });
};
if (loading) {
@@ -72,6 +81,7 @@ export function SipCredentialsCard({ details, loading }) {
+
@@ -87,10 +97,11 @@ export function SipCredentialsCard({ details, loading }) {
Use these details to connect your SIP client.
- } label="SIP Server" value="pbx.litenet.tel" onCopy={() => copyToClipboard('pbx.litenet.tel')} />
- } label="SIP Username" value={details?.extensionId} onCopy={() => copyToClipboard(details?.extensionId)} />
+ } label="SIP Server" value="pbx.litenet.tel" onCopy={() => copyToClipboard('pbx.litenet.tel', 'server')} isCopied={copiedState['server']} />
+ } label="SIP Username" value={details?.extensionId} onCopy={() => copyToClipboard(details?.extensionId, 'username')} isCopied={copiedState['username']} />
+ } label="SIP Secret" value="••••••••••••" onCopy={() => copyToClipboard(details?.user?.extPassword, 'secret')} isCopied={copiedState['secret']} />
-