Skip to content

chat #5

Description

@codedeman

import SwiftUI

// Sample Data (for preview purposes)
let sampleData = ReferralCampaignData(
availableCampaigns: [
ReferralCampaign(
availableTime: "1 June - 31 August 2025",
remainingInvites: "5 invites out of 30 limit",
invitedFriends: [
InvitedFriend(
avatar: "profile1",
name: "Shirley Wong",
campaignStatus: .inProgress,
totalReceivedAmt: "$68",
receivedTiers: [
ReceivedTier(name: "Cash Credit", receivedAmt: "$20"),
ReceivedTier(name: "Stock Coupon", receivedAmt: "$28"),
ReceivedTier(name: "Water Bottle", receivedAmt: "$20")
]
),
InvitedFriend(
avatar: "profile2",
name: "Brenda Chong",
campaignStatus: .inProgress,
totalReceivedAmt: "$20",
receivedTiers: []
)
]
)
],
receivedHistory: [
ReceivedHistory(
avatar: "profile3",
name: "Francis",
campaignStatus: .completed,
totalReceivedAmt: "$78"
),
ReceivedHistory(
avatar: "profile1",
name: "Shirley Wong",
campaignStatus: .completed,
totalReceivedAmt: "$68"
)
],
totalReceivedAmt: "1000 SGD"
)

struct InviteView: View {
let data: ReferralCampaignData

var body: some View {
    VStack(alignment: .leading) {
        // Title and Campaign Information
        Text("My Invites")
            .font(.largeTitle)
            .padding(.horizontal)
        
        ForEach(data.availableCampaigns, id: \.availableTime) { campaign in
            Text("Active Referral Campaigns (\(campaign.remainingInvites))")
                .font(.subheadline)
                .foregroundColor(.gray)
                .padding(.horizontal)
            
            // Active Referrals
            ScrollView {
                VStack {
                    ForEach(campaign.invitedFriends, id: \.name) { friend in
                        ReferralItemView(friend: friend)
                    }
                }
                .padding(.horizontal)
            }
        }
        
        // Expired Referral Campaigns
        Text("Expired Referral Campaigns")
            .font(.subheadline)
            .foregroundColor(.gray)
            .padding(.horizontal)
        
        VStack {
            ForEach(data.receivedHistory, id: \.name) { history in
                ExpiredReferralItemView(history: history)
            }
        }
        .padding(.horizontal)
        
        // Total Value Received
        Spacer()
        HStack {
            Spacer()
            Text("Total Value Received")
                .font(.headline)
                .foregroundColor(.gray)
            Text(data.totalReceivedAmt)
                .font(.title)
                .bold()
                .foregroundColor(.orange)
                .padding(.trailing)
        }
        .padding(.bottom)
    }
}

}

struct ReferralItemView: View {
let friend: InvitedFriend

var body: some View {
    HStack {
        // Profile Image
        Image(friend.avatar)
            .resizable()
            .frame(width: 40, height: 40)
            .clipShape(Circle())
        
        // User Details
        VStack(alignment: .leading) {
            Text(friend.name)
                .font(.headline)
            Text("You received \(friend.totalReceivedAmt)")
                .font(.subheadline)
                .foregroundColor(.green)
        }
        
        Spacer()
        
        // Status Button
        Text(friend.campaignStatus == .completed ? "Completed" : "In Progress")
            .padding(8)
            .background(friend.campaignStatus == .completed ? Color.green : Color.blue)
            .foregroundColor(.white)
            .cornerRadius(8)
    }
    .padding(.vertical, 5)
}

}

struct ExpiredReferralItemView: View {
let history: ReceivedHistory

var body: some View {
    HStack {
        // Profile Image
        Image(history.avatar)
            .resizable()
            .frame(width: 40, height: 40)
            .clipShape(Circle())
        
        // User Details
        VStack(alignment: .leading) {
            Text(history.name)
                .font(.headline)
            Text("You received \(history.totalReceivedAmt)")
                .font(.subheadline)
                .foregroundColor(.green)
        }
        
        Spacer()
        
        // Status Button
        Text(history.campaignStatus == .completed ? "Completed" : "In Progress")
            .padding(8)
            .background(history.campaignStatus == .completed ? Color.green : Color.blue)
            .foregroundColor(.white)
            .cornerRadius(8)
    }
    .padding(.vertical, 5)
}

}

struct InviteView_Previews: PreviewProvider {
static var previews: some View {
InviteView(data: sampleData)
}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions