|
|
@@ -14,9 +14,14 @@ import {
|
|
|
NCoreUIKitLocalize,
|
|
|
NCoreUIKitTheme
|
|
|
} from "../../core/hooks";
|
|
|
+import {
|
|
|
+ useContext as useCoreComplexContext
|
|
|
+} from "../../core/contexts/coreComplex";
|
|
|
import {
|
|
|
ChevronDown as ChevronDownIcon,
|
|
|
- ChevronLeft as ChevronLeftIcon
|
|
|
+ ChevronLeft as ChevronLeftIcon,
|
|
|
+ UserPlus as UserPlusIcon,
|
|
|
+ LogIn as LogInIcon
|
|
|
} from "lucide-react-native";
|
|
|
import {
|
|
|
STATUS_CHEAT_SHEET
|
|
|
@@ -27,10 +32,18 @@ import Button from "../button";
|
|
|
import Text from "../text";
|
|
|
|
|
|
const UserShortcut = ({
|
|
|
+ isShowLoginButtonWhenNoSession = true,
|
|
|
+ isShowRegisterButton = false,
|
|
|
+ isWorkWithCoreComplex = true,
|
|
|
spreadBehaviour = "baseline",
|
|
|
+ isShowLogoutButton = true,
|
|
|
+ isShowArrowButton = true,
|
|
|
backgroundColor = "mid",
|
|
|
+ isSessionActive = true,
|
|
|
+ onRegisterPress,
|
|
|
actionButtons,
|
|
|
onLogoutPress,
|
|
|
+ onLoginPress,
|
|
|
avatarProps,
|
|
|
customTheme,
|
|
|
statusColor,
|
|
|
@@ -48,6 +61,10 @@ const UserShortcut = ({
|
|
|
setIsBottomSheetOpen
|
|
|
] = useState(false);
|
|
|
|
|
|
+ const {
|
|
|
+ client: coreComplexClient
|
|
|
+ } = useCoreComplexContext();
|
|
|
+
|
|
|
const {
|
|
|
radiuses,
|
|
|
spaces,
|
|
|
@@ -72,6 +89,13 @@ const UserShortcut = ({
|
|
|
"success"
|
|
|
);
|
|
|
|
|
|
+ const resolvedIsSessionActive = isWorkWithCoreComplex ?
|
|
|
+ !!coreComplexClient?.variables?.accessToken
|
|
|
+ :
|
|
|
+ isSessionActive;
|
|
|
+
|
|
|
+ const isNoSession = !resolvedIsSessionActive;
|
|
|
+
|
|
|
const {
|
|
|
subTitleContainer: subTitleContainerDynamicStyle,
|
|
|
actionContainer: actionContainerDynamicStyle,
|
|
|
@@ -88,7 +112,7 @@ const UserShortcut = ({
|
|
|
});
|
|
|
|
|
|
const renderSubTitle = () => {
|
|
|
- if(!subTitle && !resolvedStatusText) {
|
|
|
+ if(isNoSession || (!subTitle && !resolvedStatusText)) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -143,6 +167,10 @@ const UserShortcut = ({
|
|
|
};
|
|
|
|
|
|
const renderContent = () => {
|
|
|
+ if(isNoSession) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
return <View
|
|
|
style={stylesheet.contentContainer}
|
|
|
>
|
|
|
@@ -159,6 +187,71 @@ const UserShortcut = ({
|
|
|
};
|
|
|
|
|
|
const renderAction = () => {
|
|
|
+ if(isNoSession) {
|
|
|
+ if(!isShowLoginButtonWhenNoSession && !isShowRegisterButton) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View
|
|
|
+ style={[
|
|
|
+ stylesheet.actionContainer,
|
|
|
+ actionContainerDynamicStyle,
|
|
|
+ {
|
|
|
+ marginLeft: spaces.spacingXs,
|
|
|
+ gap: spaces.spacingMd,
|
|
|
+ flexDirection: "row"
|
|
|
+ }
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ {
|
|
|
+ isShowLoginButtonWhenNoSession ?
|
|
|
+ <Button
|
|
|
+ icon={({
|
|
|
+ color,
|
|
|
+ size
|
|
|
+ }) => {
|
|
|
+ return <LogInIcon
|
|
|
+ color={colors.content.icon[color]}
|
|
|
+ size={size + 2}
|
|
|
+ />;
|
|
|
+ }}
|
|
|
+ onPress={() => onLoginPress?.()}
|
|
|
+ title={localize("login")}
|
|
|
+ spreadBehaviour="free"
|
|
|
+ type="neutral"
|
|
|
+ size="small"
|
|
|
+ />
|
|
|
+ :
|
|
|
+ null
|
|
|
+ }
|
|
|
+ {
|
|
|
+ isShowRegisterButton ?
|
|
|
+ <Button
|
|
|
+ icon={({
|
|
|
+ color,
|
|
|
+ size
|
|
|
+ }) => {
|
|
|
+ return <UserPlusIcon
|
|
|
+ color={colors.content.icon[color]}
|
|
|
+ size={size + 2}
|
|
|
+ />;
|
|
|
+ }}
|
|
|
+ onPress={() => onRegisterPress?.()}
|
|
|
+ title={localize("register")}
|
|
|
+ spreadBehaviour="free"
|
|
|
+ type="neutral"
|
|
|
+ size="small"
|
|
|
+ />
|
|
|
+ :
|
|
|
+ null
|
|
|
+ }
|
|
|
+ </View>;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!isShowArrowButton) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
return <View
|
|
|
style={[
|
|
|
stylesheet.actionContainer,
|
|
|
@@ -173,13 +266,13 @@ const UserShortcut = ({
|
|
|
if(isBottomSheetOpen) {
|
|
|
return <ChevronDownIcon
|
|
|
color={colors.content.icon[color]}
|
|
|
- size={size}
|
|
|
+ size={size + 5}
|
|
|
/>;
|
|
|
}
|
|
|
|
|
|
return <ChevronLeftIcon
|
|
|
color={colors.content.icon[color]}
|
|
|
- size={size}
|
|
|
+ size={size + 5}
|
|
|
/>;
|
|
|
}}
|
|
|
onPress={() => {
|
|
|
@@ -194,7 +287,7 @@ const UserShortcut = ({
|
|
|
};
|
|
|
|
|
|
const renderBadges = () => {
|
|
|
- if(!badges || badges.length === 0) {
|
|
|
+ if(isNoSession || !badges || badges.length === 0) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -215,6 +308,10 @@ const UserShortcut = ({
|
|
|
};
|
|
|
|
|
|
const renderBottomSheet = () => {
|
|
|
+ if(isNoSession || !isShowArrowButton) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
return <BottomSheet
|
|
|
onClose={() => setIsBottomSheetOpen(false)}
|
|
|
isActive={isBottomSheetOpen}
|
|
|
@@ -236,22 +333,50 @@ const UserShortcut = ({
|
|
|
/>;
|
|
|
})
|
|
|
}
|
|
|
- <Button
|
|
|
- title={localize("logout" as keyof NCoreUIKit.Translation)}
|
|
|
- onPress={() => {
|
|
|
- setIsBottomSheetOpen(false);
|
|
|
- if(onLogoutPress) onLogoutPress();
|
|
|
- }}
|
|
|
- spreadBehaviour="stretch"
|
|
|
- type="danger"
|
|
|
- />
|
|
|
+ {
|
|
|
+ isShowLogoutButton ?
|
|
|
+ <Button
|
|
|
+ title={localize("logout" as keyof NCoreUIKit.Translation)}
|
|
|
+ onPress={async () => {
|
|
|
+ setIsBottomSheetOpen(false);
|
|
|
+
|
|
|
+ let response;
|
|
|
+ let error;
|
|
|
+
|
|
|
+ if(isWorkWithCoreComplex && coreComplexClient) {
|
|
|
+ try {
|
|
|
+ response = await (
|
|
|
+ coreComplexClient.NAuth as unknown as {
|
|
|
+ logout: () => Promise<unknown>;
|
|
|
+ }
|
|
|
+ ).logout();
|
|
|
+ } catch(e) {
|
|
|
+ error = e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(onLogoutPress) {
|
|
|
+ onLogoutPress(response, error);
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ spreadBehaviour="stretch"
|
|
|
+ type="danger"
|
|
|
+ />
|
|
|
+ :
|
|
|
+ null
|
|
|
+ }
|
|
|
</View>
|
|
|
</BottomSheet>;
|
|
|
};
|
|
|
|
|
|
return <Fragment>
|
|
|
<TouchableOpacity
|
|
|
+ activeOpacity={isNoSession && (isShowLoginButtonWhenNoSession || isShowRegisterButton) ? 1 : 0.2}
|
|
|
onPress={isDisabled ? undefined : () => {
|
|
|
+ if(isNoSession && (isShowLoginButtonWhenNoSession || isShowRegisterButton)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if(onPress) onPress();
|
|
|
}}
|
|
|
style={[
|
|
|
@@ -265,7 +390,12 @@ const UserShortcut = ({
|
|
|
style={stylesheet.avatarContainer}
|
|
|
>
|
|
|
<Avatar
|
|
|
- {...avatarProps}
|
|
|
+ {...(isNoSession ? {
|
|
|
+ ...avatarProps,
|
|
|
+ statusIndicatorType: undefined,
|
|
|
+ title: undefined,
|
|
|
+ url: undefined
|
|
|
+ } : avatarProps)}
|
|
|
size="small"
|
|
|
/>
|
|
|
{renderBadges()}
|