diff --git a/src/components/customSwitch.tsx b/src/components/customSwitch.tsx new file mode 100644 index 00000000..170bb8da --- /dev/null +++ b/src/components/customSwitch.tsx @@ -0,0 +1,50 @@ +const icon = ( + + + + +); + +export function CustomSwitch({ handleToggle, isChecked }): JSX.Element { + // const [isChecked, setIsChecked] = useState(false); + // const [selectedIcon, setSelectedIcon] = useState(icon); + + // const handleToggle = () => { + // const updateChecked = !isChecked; + // setIsChecked(updateChecked); + // // setTimeout(() => { + // // setSelectedIcon(updateChecked ? icon : icon); + // // }, 250); + // }; + + return ( + + ); +} diff --git a/src/components/signinCard.tsx b/src/components/signinCard.tsx index edbabde0..3b035cd3 100644 --- a/src/components/signinCard.tsx +++ b/src/components/signinCard.tsx @@ -1,4 +1,10 @@ -export function SigninCard({ signin, handleDelete }): JSX.Element { +import { CustomSwitch } from "@components/customSwitch"; + +export function SigninCard({ + signin, + handleDelete, + handleAutoSignin, +}): JSX.Element { return (
@@ -22,21 +28,30 @@ export function SigninCard({ signin, handleDelete }): JSX.Element {
-
-

- {signin?.identifier ? "Identifier Alias" : "Credential"} -

-

- {signin?.identifier?.name} -

-
+
+

+ {signin?.identifier ? "Identifier Alias" : "Credential"} +

+

+ {signin?.identifier?.name} +

+

Last Used

{new Date(signin?.updatedAt).toDateString()}

+
+
+
+

Auto Sign in

+ +
))} diff --git a/src/pages/background/index.ts b/src/pages/background/index.ts index 7ce29234..f7db19be 100644 --- a/src/pages/background/index.ts +++ b/src/pages/background/index.ts @@ -5,7 +5,7 @@ import { signifyService } from "@pages/background/services/signify"; import { IMessage } from "@pages/background/types"; import { senderIsPopup } from "@pages/background/utils"; import { getCurrentDomain } from "@pages/background/utils"; -import { deleteSigninByIndex } from "@pages/background/signins-utils"; +import { updateDomainAutoSigninByIndex, deleteSigninByIndex } from "@pages/background/signins-utils"; console.log("Background script loaded"); @@ -148,6 +148,15 @@ chrome.runtime.onMessage.addListener(function ( }); } + if (message.type === "update-resource" && message.subtype === "auto-signin") { + const resp = await updateDomainAutoSigninByIndex(message?.data?.index, message?.data?.signin); + sendResponse({ + data: { + ...resp, + }, + }); + } + if (message.type === "delete-resource" && message.subtype === "signins") { const resp = await deleteSigninByIndex(message?.data?.index); sendResponse({ diff --git a/src/pages/background/signins-utils.ts b/src/pages/background/signins-utils.ts index a8c056b2..f3c30b1c 100644 --- a/src/pages/background/signins-utils.ts +++ b/src/pages/background/signins-utils.ts @@ -1,5 +1,23 @@ import { browserStorageService } from "@pages/background/services/browser-storage"; +export const updateDomainAutoSigninByIndex = async (index: number, signin) => { + let signins = await browserStorageService.getValue("signins"); + if (signins?.length) { + const newSignins = signins.map((_ele, idx) => { + if (idx !== index && _ele.domain !== signin.domain) return _ele; + + if (idx !== index && _ele.domain === signin.domain) + return { ..._ele, autoSignin: false }; + + return { ..._ele, autoSignin: true }; + }); + await browserStorageService.setValue("signins", newSignins); + } + signins = await browserStorageService.getValue("signins"); + + return { signins }; +}; + export const deleteSigninByIndex = async (index: number) => { let signins = await browserStorageService.getValue("signins"); let deleted = false; diff --git a/src/pages/dialog/signin.tsx b/src/pages/dialog/signin.tsx index 428775b4..adc6e5a6 100644 --- a/src/pages/dialog/signin.tsx +++ b/src/pages/dialog/signin.tsx @@ -1,7 +1,6 @@ import { TAB_STATE } from "@pages/popup/constants"; import { setTabState } from "@pages/content/index"; - // TODO do not pass the full signins stored object (only AID name, schema name, web url) export const SigninItem = ({ signin }: { signin: any }): JSX.Element => { const handleClick = async () => { @@ -21,7 +20,7 @@ export const SigninItem = ({ signin }: { signin: any }): JSX.Element => { return (
-
+

URL: {signin.domain}

{signin?.identifier ? (

@@ -41,13 +40,35 @@ export const SigninItem = ({ signin }: { signin: any }): JSX.Element => { Last used: {new Date(signin.updatedAt).toDateString()}

- +
+
+

Auto Sign in

+
+ + + +
+
+ + +
); };