unoffical wafrn mirror wafrn.net
atproto social-network activitypub
at development 77 lines 2.8 kB view raw
1import { Component, Inject, OnInit, Signal } from '@angular/core' 2import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, UntypedFormGroup, Validators } from '@angular/forms' 3import { MatButtonModule } from '@angular/material/button' 4import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog' 5import { MatFormFieldModule } from '@angular/material/form-field' 6import { MatInput } from '@angular/material/input' 7import { BlogDetails } from 'src/app/interfaces/blogDetails' 8import { BlogService } from 'src/app/services/blog.service' 9import { LoginService } from 'src/app/services/login.service' 10import { MessageService } from 'src/app/services/message.service' 11import { InfoCardComponent } from '../info-card/info-card.component' 12import { TranslateModule } from '@ngx-translate/core' 13import { MatCheckboxModule } from '@angular/material/checkbox' 14import { ParticleService } from 'src/app/services/particle.service' 15import { MatDatepicker, MatDatepickerModule, MatDateRangeInput } from "@angular/material/datepicker"; 16import { AdminService } from 'src/app/services/admin.service' 17 18@Component({ 19 selector: 'app-add-invite-code', 20 imports: [ 21 FormsModule, 22 ReactiveFormsModule, 23 MatInput, 24 MatFormFieldModule, 25 MatButtonModule, 26 TranslateModule, 27 MatCheckboxModule, 28 MatDatepicker, 29 MatDatepickerModule 30 ], 31 templateUrl: './add-invite-code.component.html', 32 styleUrl: './add-invite-code.component.scss' 33}) 34export class AddInviteCodeComponent implements OnInit { 35 allowAnons = false 36 constructor( 37 private dialogRef: MatDialogRef<AddInviteCodeComponent>, 38 private messages: MessageService, 39 @Inject(MAT_DIALOG_DATA) 40 public data: { 41 details: BlogDetails 42 }, 43 private blogService: BlogService, 44 protected loginService: LoginService, 45 private particle: ParticleService, 46 protected adminService: AdminService 47 ) { 48 49 } 50 ngOnInit(): void { 51 const allowAnonsOption = this.data.details.publicOptions.find((elem) => elem.optionName === 'wafrn.public.asks') 52 if (allowAnonsOption) { 53 this.allowAnons = allowAnonsOption.optionValue == '1' 54 } 55 } 56 57 addInviteCode = new FormGroup({ 58 code: new FormControl('', [Validators.minLength(6)]), 59 expirationDate: new FormControl((() => { 60 const currentDate = new Date() 61 currentDate.setDate(currentDate.getDate() + 7) 62 return currentDate 63 })()) 64 }) 65 66 async onSubmit() { 67 const res = await this.adminService.addInviteCode(this.addInviteCode.value.code ?? undefined, this.addInviteCode.value.expirationDate ?? undefined) 68 if (res) { 69 this.messages.add({ 70 severity: 'success', 71 summary: 'Created invite code!' 72 }) 73 this.dialogRef.close() 74 window.location.reload() 75 } 76 } 77}