mirror of
https://github.com/jambonz/chrome-extension-dialer.git
synced 2025-12-18 20:37:45 +00:00
Merge pull request #37 from jambonz/feat/fix_null_settings
fixed null setting if remove active account
This commit is contained in:
@@ -91,12 +91,18 @@ export const setActiveSettings = (id: number) => {
|
||||
export const deleteSettings = (id: number) => {
|
||||
const str = localStorage.getItem(SETTINGS_KEY);
|
||||
if (str) {
|
||||
const parsed = JSON.parse(str);
|
||||
const parsed = JSON.parse(str) as saveSettingFormat[];
|
||||
|
||||
// for edit:
|
||||
const newData = parsed.filter((el: saveSettingFormat) => el.id !== id);
|
||||
const setting = parsed.find((s) => s.id === id);
|
||||
|
||||
localStorage.setItem(SETTINGS_KEY, JSON.stringify(newData));
|
||||
const newSettings = parsed.filter((el) => el.id !== id);
|
||||
|
||||
// deleting active account, reassign active to next account
|
||||
if (setting?.active && newSettings.length) {
|
||||
newSettings[0].active = true;
|
||||
}
|
||||
|
||||
localStorage.setItem(SETTINGS_KEY, JSON.stringify(newSettings));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -126,14 +132,16 @@ export const getActiveSettings = (): IAppSettings => {
|
||||
JSON.parse(str);
|
||||
|
||||
const activeSettings = parsed.find((el) => el.active);
|
||||
const decoded = {
|
||||
active: activeSettings?.active,
|
||||
decoded: JSON.parse(
|
||||
Buffer.from(activeSettings?.encoded!, "base64").toString("utf-8")
|
||||
),
|
||||
id: activeSettings?.id,
|
||||
};
|
||||
return decoded as IAppSettings;
|
||||
if (activeSettings) {
|
||||
const decoded = {
|
||||
active: activeSettings?.active,
|
||||
decoded: JSON.parse(
|
||||
Buffer.from(activeSettings.encoded, "base64").toString("utf-8")
|
||||
),
|
||||
id: activeSettings.id,
|
||||
};
|
||||
return decoded as IAppSettings;
|
||||
}
|
||||
}
|
||||
return {} as IAppSettings;
|
||||
};
|
||||
|
||||
@@ -120,7 +120,6 @@ export const Phone = forwardRef(
|
||||
) => {
|
||||
const [inputNumber, setInputNumber] = useState("");
|
||||
const [appName, setAppName] = useState("");
|
||||
const [isConfigured, setIsConfigured] = useState(false);
|
||||
const [callStatus, setCallStatus] = useState(SipConstants.SESSION_ENDED);
|
||||
const [sessionDirection, setSessionDirection] =
|
||||
useState<SipCallDirection>("");
|
||||
@@ -145,6 +144,7 @@ export const Phone = forwardRef(
|
||||
const sessionDirectionRef = useRef(sessionDirection);
|
||||
const sipUA = useRef<SipUA | null>(null);
|
||||
const timerRef = useRef<NodeJS.Timer | null>(null);
|
||||
const FetchUsertimerRef = useRef<NodeJS.Timer | null>(null);
|
||||
const isRestartRef = useRef(false);
|
||||
const sipDomainRef = useRef("");
|
||||
const sipUsernameRef = useRef("");
|
||||
@@ -299,7 +299,7 @@ export const Phone = forwardRef(
|
||||
setStatus,
|
||||
startCallDurationCounter,
|
||||
toast,
|
||||
setIsOnline
|
||||
setIsOnline,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -319,19 +319,9 @@ export const Phone = forwardRef(
|
||||
} else {
|
||||
createSipClient();
|
||||
}
|
||||
setIsConfigured(true);
|
||||
} else {
|
||||
setIsConfigured(false);
|
||||
clientGoOffline();
|
||||
}
|
||||
fetchRegisterUser();
|
||||
getConferences()
|
||||
?.then(() => {
|
||||
setShowConference(true);
|
||||
})
|
||||
.catch(() => {
|
||||
setShowConference(false);
|
||||
});
|
||||
}, [
|
||||
sipDomain,
|
||||
sipUsername,
|
||||
@@ -405,14 +395,31 @@ export const Phone = forwardRef(
|
||||
}
|
||||
}, [status, setIsOnline, setIsSwitchingUserStatus]);
|
||||
|
||||
const clearFetchUserTimer = () => {
|
||||
if (FetchUsertimerRef.current) {
|
||||
clearInterval(FetchUsertimerRef.current);
|
||||
FetchUsertimerRef.current = null;
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => {
|
||||
fetchRegisterUser();
|
||||
}, 10000);
|
||||
return () => {
|
||||
clearInterval(timer);
|
||||
};
|
||||
}, []);
|
||||
if (isAdvanceMode) {
|
||||
// check conference aibility
|
||||
getConferences()
|
||||
.then(() => {
|
||||
setShowConference(true);
|
||||
})
|
||||
.catch(() => {
|
||||
setShowConference(false);
|
||||
});
|
||||
FetchUsertimerRef.current = setInterval(() => {
|
||||
fetchRegisterUser();
|
||||
}, 10_000);
|
||||
} else {
|
||||
clearFetchUserTimer();
|
||||
setShowConference(false);
|
||||
}
|
||||
}, [isAdvanceMode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (showAccounts) {
|
||||
@@ -553,9 +560,7 @@ export const Phone = forwardRef(
|
||||
const handleSetActive = (id: number) => {
|
||||
setActiveSettings(id);
|
||||
setShowAccounts(false);
|
||||
// fetchRegisterUser();
|
||||
reload();
|
||||
// window.location.reload();
|
||||
};
|
||||
|
||||
const handleClickOutside = (event: Event) => {
|
||||
|
||||
Reference in New Issue
Block a user