diff --git a/src/api/marketplace/accounts/serializers.py b/src/api/marketplace/accounts/serializers.py index 394d9494..67585f4f 100644 --- a/src/api/marketplace/accounts/serializers.py +++ b/src/api/marketplace/accounts/serializers.py @@ -25,46 +25,6 @@ from django.shortcuts import get_object_or_404 from django.db.models import Avg - -class BusinessAccountMetaDataSerializer(serializers.ModelSerializer): - influencer_ids = serializers.SerializerMethodField(read_only=True) - is_twitter_connected = serializers.SerializerMethodField(read_only=True) - is_wallet_connected = serializers.SerializerMethodField(read_only=True) - - class Meta: - model = BusinessAccountMetaData - fields = "__all__" - - def get_influencer_ids(self, business_meta_data): - completed_orders = Order.objects.filter( - buyer=business_meta_data.user_account, status="completed" - ) - influencer_ids = set() - - for completed_order in completed_orders: - completed_order_items = OrderItem.objects.filter(order_id=completed_order) - package_ids = completed_order_items.values_list("package_id", flat=True) - influencers = Package.objects.filter(id__in=package_ids).values_list( - "influencer_id", flat=True - ) - influencer_ids.update(influencers) - - return list(influencer_ids) - - def get_is_twitter_connected(self, business_meta_data): - userAccount = business_meta_data.user_account - if userAccount.twitter_account: - return True - return False - - - def get_is_wallet_connected(self, business_meta_data): - user_wallet = Wallet.objects.filter(user_id = business_meta_data.user_account) - if(user_wallet): - return True - return False - - class CategoryMasterSerializer(serializers.ModelSerializer): class Meta: model = CategoryMaster @@ -268,6 +228,52 @@ def update(self, instance, validated_data): return instance +class BusinessAccountMetaDataSerializer(serializers.ModelSerializer): + influencer_ids = serializers.SerializerMethodField(read_only=True) + is_twitter_connected = serializers.SerializerMethodField(read_only=True) + is_wallet_connected = serializers.SerializerMethodField(read_only=True) + user_twitter_profile_image = serializers.SerializerMethodField(read_only=True) + user_account = UserSerializer(read_only=True) + + class Meta: + model = BusinessAccountMetaData + fields = "__all__" + + def get_influencer_ids(self, business_meta_data): + completed_orders = Order.objects.filter( + buyer=business_meta_data.user_account, status="completed" + ) + influencer_ids = set() + + for completed_order in completed_orders: + completed_order_items = OrderItem.objects.filter(order_id=completed_order) + package_ids = completed_order_items.values_list("package_id", flat=True) + influencers = Package.objects.filter(id__in=package_ids).values_list( + "influencer_id", flat=True + ) + influencer_ids.update(influencers) + + return list(influencer_ids) + + def get_is_twitter_connected(self, business_meta_data): + userAccount = business_meta_data.user_account + if userAccount.twitter_account: + return True + return False + + + def get_is_wallet_connected(self, business_meta_data): + user_wallet = Wallet.objects.filter(user_id = business_meta_data.user_account) + if(user_wallet): + return True + return False + + def get_user_twitter_profile_image(self, business_meta_data): + userAccount = business_meta_data.user_account + try: + return userAccount.twitter_account.profile_image_url + except Exception as e: + return "" class TwitterReadSerializer(serializers.ModelSerializer): class Meta: diff --git a/src/ui/app/business/profile-preview/[id]/page.tsx b/src/ui/app/business/profile-preview/[id]/page.tsx index f6d360a4..7eedbec9 100644 --- a/src/ui/app/business/profile-preview/[id]/page.tsx +++ b/src/ui/app/business/profile-preview/[id]/page.tsx @@ -27,6 +27,7 @@ import Image from "next/image"; import NotFound from "@/public/svg/not_found.svg"; import { stringToColor } from "@/src/utils/helper"; import { BADGES } from "@/src/utils/consts"; +import { getProfileCompletedStatus } from "@/src/services/profileCompletion"; type Props = { params: { @@ -48,22 +49,6 @@ const styles = { }, }; -const getProfileCompletedStatus: (businessDetails: any) => string = ( - businessDetails -) => { - if (businessDetails) { - let count = 0; - if (businessDetails?.isTwitterAccountConnected) count += 5; - if (businessDetails?.isWalletConnected) count += 5; - count += - Object.values(businessDetails).filter( - (value) => value !== "" && value !== null - ).length - 7; - return `${count} / ${10 + Object.keys(businessDetails).length - 7}`; - } - return "-"; -}; - const formatTwitterFollowers = (followersCount: any) => { if (followersCount >= 1000000) { // Convert to millions format @@ -80,8 +65,7 @@ const formatTwitterFollowers = (followersCount: any) => { export default function BusinessProfilePreview({ params }: Props) { const [isProfileComplete, setIsProfileComplete] = useState(false); const [collaborations, setCollaborations] = useState([]); - const [businessDetails, setBusinessDetails] = - useState(); + const [businessDetails, setBusinessDetails] = useState(); const user = useAppSelector((state) => state.user?.user); const router = useRouter(); @@ -104,6 +88,8 @@ export default function BusinessProfilePreview({ params }: Props) { .replace(/\s/g, "") .split("/"); + console.log(completionStringArr); + return ( (parseInt(completionStringArr[0]) / parseInt(completionStringArr[1])) * 100 @@ -160,8 +146,6 @@ export default function BusinessProfilePreview({ params }: Props) { if (isSuccess) { setBusinessDetails({ ...data?.data, - isTwitterAccountConnected: !!user?.twitter_account, - isWalletConnected: !!user?.wallets?.length, }); getCollaborators(data?.data?.influencer_ids); } @@ -211,10 +195,10 @@ export default function BusinessProfilePreview({ params }: Props) { alignItems: "center", }} > - {user?.twitter_account?.profile_image_url ? ( + {!!businessDetails?.user_twitter_profile_image ? ( ) : ( )} @@ -412,7 +398,7 @@ export default function BusinessProfilePreview({ params }: Props) { margin: "20px", }} > - {user?.role?.name === "business_owner" ? ( + {user?.id == params?.id ? (