diff --git a/src/app/campaigns/campaigns.module.ts b/src/app/campaigns/campaigns.module.ts index 4fc7ce4e7..2c907b1e7 100755 --- a/src/app/campaigns/campaigns.module.ts +++ b/src/app/campaigns/campaigns.module.ts @@ -18,7 +18,7 @@ import { ParticiperComponent } from '@app/campaigns/components/participer/partic import { PasswordModalComponent } from './components/password-modal/password-modal.component'; import { TransactionMessageStatusComponent } from '@app/campaigns/components/transaction-message-status/transaction-message-status.component'; import { NgxTweetModule } from 'ngx-tweet'; - +import { DraftMaximumParticipationComponent } from '@app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component'; import { CampaignsSharedUiModule } from './campaigns-shared-ui.module'; import { NpnSliderModule } from 'npn-slider'; import { EffectsModule } from '@ngrx/effects'; @@ -56,7 +56,8 @@ import { SharedModule } from '@app/shared/shared.module'; TransactionMessageStatusComponent, MissionsComponent, DraftPictureComponent, - SocialsComponent + SocialsComponent, + DraftMaximumParticipationComponent ], imports: [ CommonModule, diff --git a/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.css b/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.css new file mode 100644 index 000000000..75d4cfd4a --- /dev/null +++ b/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.css @@ -0,0 +1,67 @@ +.title-section { + font-style: normal; + font-weight: bold; + font-size: 22px; + line-height: 28px; + text-align: center; + letter-spacing: 1px; + color: #1f2337; +} +.label-type { + font-style: normal; + font-family: 'Poppins'; + font-weight: 400; + font-size: 16px; + line-height: 125.9%; + letter-spacing: 0.03em; + color: #75758f; + text-align: center; + display: flow; + margin-bottom: 25px !important; +} +.small-label { + font-style: normal; + font-weight: 600; + font-size: 14px; + line-height: 125.9%; + letter-spacing: 0.03em; + color: #75758F; + padding-left: 170px !important; +} +.styleForInputMedia { + border-style: solid; + border-radius: 30px; + border-color: #D6D6E8; + outline: none; + width: 40%; + height: 150%; + text-align: start; + color: #323754; + margin-right: 30px !important; + position: relative; + bottom: 0.4em; + text-align: center; + } + + /* .cont{ + display : flex; + flex-direction: row; + } */ + + .test{ display: flex; justify-content: flex-end;} + .left { flex-grow: 1; } + .right { display: flex; align-items: center; } + + + /* Hide the spinner controls for number input */ +input[type="number"]::-webkit-inner-spin-button, +input[type="number"]::-webkit-outer-spin-button { + -webkit-appearance: none; + appearance: none; + margin: 0; +} + +/* Hide the spinner controls for Firefox */ +input[type="number"] { + -moz-appearance: textfield; +} diff --git a/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.html b/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.html new file mode 100644 index 000000000..d3cb1fccc --- /dev/null +++ b/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.html @@ -0,0 +1,58 @@ +
+
+ +
+
+
+ +
+
+
+ + + +
+
+

{{ 'campaign_descrip-max-partic' | translate }}

+
+
+ + + + +
diff --git a/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.spec.ts b/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.spec.ts new file mode 100644 index 000000000..dd4a762f9 --- /dev/null +++ b/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { DraftMaximumParticipationComponent } from './draft-maximum-participation.component'; + +describe('DraftMaximumParticipationComponent', () => { + let component: DraftMaximumParticipationComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ DraftMaximumParticipationComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(DraftMaximumParticipationComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.ts b/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.ts new file mode 100644 index 000000000..10c472458 --- /dev/null +++ b/src/app/campaigns/components/draft-maximum-participation/draft-maximum-participation.component.ts @@ -0,0 +1,96 @@ +import { Component, OnInit,ViewChild,Output,EventEmitter,OnDestroy } from '@angular/core'; +import { UntypedFormArray, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; +import { ActivatedRoute } from '@angular/router'; +import { CampaignHttpApiService } from '@core/services/campaign/campaign.service'; +import { debounceTime, distinctUntilChanged, switchMap, takeUntil, tap } from 'rxjs/operators'; +import { Subject,Subscription } from 'rxjs'; +import { DraftCampaignService } from '@campaigns/services/draft-campaign.service'; + + +@Component({ + selector: 'app-draft-maximum-participation', + templateUrl: './draft-maximum-participation.component.html', + styleUrls: ['./draft-maximum-participation.component.css'] +}) + + +export class DraftMaximumParticipationComponent implements OnInit { + + private inputValueSubject = new Subject(); + private inputValueSubscription: Subscription | undefined; + private isDestroyed = new Subject(); + + form = new UntypedFormGroup({ + limitParticipation: new UntypedFormControl(0, [Validators.required]) + }); + constructor(private route: ActivatedRoute, + private campaignService: CampaignHttpApiService, + private service :DraftCampaignService) { + + this.form = new UntypedFormGroup( + { + limitParticipation: new UntypedFormControl(0, { + validators: Validators.required + }), + } + ); + } + id! :any; + ngOnInit(): void { + // Accessing the ID parameter from the URL + this.id = this.route.snapshot.paramMap.get('id'); + + // Set up the subscription + this.inputValueSubscription = this.inputValueSubject + .pipe( + debounceTime(1000), // Adjust the debounce time as needed (in milliseconds) + switchMap((value) => { + console.log('SwitchMap triggered with value:', value); + + return this.saveParticipantsNumber(+value)} + ) // Convert value to a number and send the API request + ) + .subscribe(); + + } + inputValue: string = ''; + @ViewChild('toggleSwitch', { static: true }) toggleSwitch: any; +onInputChanged() { + console.log('Emitting value:', this.inputValue); + this.saveForm(); + !this.toggleSwitch.checked && (this.inputValue = ''); + this.form.get('limitParticipation')?.setValue(this.inputValue || 0) + return this.campaignService.updateOneById({limitParticipation :this.inputValue || 0},this.id).subscribe((data : any)=>{console.log(data);}) + } + + private saveParticipantsNumber(limit : number){ + console.log('here') + return this.campaignService.updateOneById({limit},this.id) + } + + + saveForm() { + this.form.valueChanges + .pipe( + debounceTime(500), + tap((values: any) => { + if (this.id) { + this.service.autoSaveFormOnValueChanges({ + formData: values, + id: this.id + }); + } + }), + takeUntil(this.isDestroyed) + ) + .subscribe(); + } + + ngOnDestroy(): void { + if (this.inputValueSubscription) { + this.inputValueSubscription.unsubscribe(); + } + this.isDestroyed.next(''); + this.isDestroyed.unsubscribe(); + } +} diff --git a/src/app/campaigns/components/edit-campaign/edit-campaign.component.html b/src/app/campaigns/components/edit-campaign/edit-campaign.component.html index 4db0f23a3..1a67f929d 100755 --- a/src/app/campaigns/components/edit-campaign/edit-campaign.component.html +++ b/src/app/campaigns/components/edit-campaign/edit-campaign.component.html @@ -67,7 +67,15 @@

- + +
+ + +
+
+
+
{ diff --git a/src/app/campaigns/services/format-data.service.ts b/src/app/campaigns/services/format-data.service.ts index 59286ddd6..1b74b63fe 100755 --- a/src/app/campaigns/services/format-data.service.ts +++ b/src/app/campaigns/services/format-data.service.ts @@ -71,6 +71,9 @@ export class FormatDataService { if (campaign.hasOwnProperty('startDate')) { object.startDate = new Date(campaign.startDate).getTime() / 1000; } + + campaign.limitParticipation && (object.limit = campaign.limitParticipation) + if (campaign.hasOwnProperty('remuneration')) { // TODO: fix remuneration not sent to backend object.remuneration = campaign.remuneration; @@ -145,7 +148,6 @@ export class FormatDataService { if (campaign.hasOwnProperty('missions')) { object.missions = campaign.missions; } - return object; } diff --git a/src/app/core/campaigns-list-response.interface.ts b/src/app/core/campaigns-list-response.interface.ts index ab6cfbcb3..c0d89c556 100755 --- a/src/app/core/campaigns-list-response.interface.ts +++ b/src/app/core/campaigns-list-response.interface.ts @@ -47,4 +47,5 @@ export interface ICampaignResponse { file?: string; urlPicUser?: string; missions?: []; + limit:number; } diff --git a/src/app/models/campaign.model.ts b/src/app/models/campaign.model.ts index 97c229dd2..691809b23 100755 --- a/src/app/models/campaign.model.ts +++ b/src/app/models/campaign.model.ts @@ -38,6 +38,7 @@ export class Campaign { ownerId: string; urlPicUser: any; type: string; + limitParticipation:number; tokenStorageService!: TokenStorageService; missions: []; isOwnedByUser = false; @@ -49,7 +50,7 @@ export class Campaign { this.ownerId = data?.idNode || ''; this.initialBudget = data?.cost || '0'; this.initialBudgetInUSD = data?.cost_usd || '0'; - + this.limitParticipation = data?.limit || 0; this.budget = data?.funds ? (data?.funds[1] as string) : data?.remaining diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 29e18df78..2634c8cb0 100755 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -314,9 +314,11 @@ "campaign.likes": "Like", "campaign.shares": "Share", "campaign.kit_de_campagne": "AdPool Kit", + "campaign.title_maximum_participation": "Maximum participation", "campaign_password.confirm": "confirm", "campaign.duration": "Duration", "campaign.ajout_desc": "Provide documents (audio, video, texts, photos) to your creators to enable them to carry out their missions in the best possible conditions.", + "campaign_descrip-max-partic":"Insert the maximum number of participations per individual", "campaign.ajout_description": "8MB per file maximum. Maximum 5 files.", "campaign.InsufficientBudget": "Insufficient budget", "campaign.minfollowers_must_maxfollowers": "Max Followers should be greater than min Followers", @@ -500,6 +502,7 @@ "campaign_details.no_summary_msg": "No summary yet!! please add one.", "campaign_details.no_description_msg": "No description yet!! please add one.", "campaign_details.add_files": "ADD FILES", + "campaign_sous_titre_max_part": "Customize participant engagement by setting a maximum limit participation numbers.", "campaign_details.add_new_links": "ADD LINKS", "campaign_details.campaign_duration_text": "Campaign duration", "campaign_details.campaign_kit": "Adpool Kit", diff --git a/src/assets/i18n/fr.json b/src/assets/i18n/fr.json index 98631bbac..293e8ac0c 100755 --- a/src/assets/i18n/fr.json +++ b/src/assets/i18n/fr.json @@ -634,6 +634,7 @@ "campaign.shares": "Partages", "campaign.reach": "Atteindre le maximum", "campaign.kit_de_campagne": "AdPool Kit", + "campaign.title_maximum_participation": "Participation maximale", "campaign_password.confirm": "confirmer", "campaign.edit_page_title": "Editer campagne", "campaign.duration_placeholder": "Jours", @@ -739,6 +740,8 @@ "campaign_details.no_description_msg": "Pas encore de description !! veuillez en ajouter un.", "reject_link": "Rejeté !", "campaign_details.add_files": "Ajouter des fichiers", + "campaign_sous_titre_max_part": "Personnalisez l’engagement des participants en définissant un nombre maximal de participants.", + "campaign_descrip-max-partic":"Insérer le nombre maximum de participations par individu", "campaign_details.add_new_links": "Ajouter des Liens", "campaign_details.campaign_duration_text": "Durée de la campagne", "campaign_details.campaign_kit": "Kit AdPool",