func newDomain()

in tui/specials.go [102:219]


func newDomain(q *Queue) {
	contact := gcloud.ContactData{}

	t := newTextInput(
		"Enter a domain you wish to purchase and use for this application",
		"",
		"domain",
		"Checking Domain Availability",
	)
	t.postProcessor = validateDomain
	q.add(&t)

	items := []struct {
		Name         string
		Description  string
		DefaultValue string
		Validator    func(string, *Queue) tea.Cmd
	}{
		{
			Name:         "domain_email",
			Description:  "Enter an email address",
			DefaultValue: "person@example.com",
		},

		{
			Name:         "domain_phone",
			Description:  "Enter a phone number. (Please enter with country code - +1 555 555 5555 for US for example)",
			DefaultValue: "+14155551234",
			Validator:    validatePhoneNumber,
		},

		{
			Name:         "domain_country",
			Description:  "Enter a country code",
			DefaultValue: "US",
		},

		{
			Name:         "domain_postalcode",
			Description:  "Enter a postal code",
			DefaultValue: "94502",
		},

		{
			Name:         "domain_state",
			Description:  "Enter a state or administrative area",
			DefaultValue: "CA",
		},

		{
			Name:         "domain_city",
			Description:  "Enter a city",
			DefaultValue: "San Francisco",
		},

		{
			Name:         "domain_address",
			Description:  "Enter an address",
			DefaultValue: "345 Spear Street",
		},

		{
			Name:         "domain_name",
			Description:  "Enter name",
			DefaultValue: "Googler",
		},
	}

	tmp := q.Get("contact")
	switch v := tmp.(type) {
	case gcloud.ContactData:
		contact = v
	default:
		contact = gcloud.ContactData{}
	}

	if contact.AllContacts.Email == "" {
		for _, v := range items {
			t := newTextInput(v.Description, v.DefaultValue, v.Name, "")
			q.add(&t)
		}
	}

	f := func(q *Queue) {
		domain := q.Get("domain").(string)
		info := q.Get("domainInfo").(*domainspb.RegisterParameters)

		if info.YearlyPrice != nil {
			msg := fmt.Sprintf(
				"Cost for %s will be %s.  %s",
				domain,
				purchaseStyle.Render(
					fmt.Sprintf(
						"%d%s",
						info.YearlyPrice.Units,
						info.YearlyPrice.CurrencyCode,
					),
				),
				textStyle.Render("Continue?"),
			)
			p := q.models[q.current]
			p.clearContent()
			p.addContent(msg)
		}
	}

	dy := newYesOrNo(
		q,
		"Buying a domain is not reversible, saying 'y' will incur a charge.",
		"domain_consent",
		false,
		nil,
	)
	dy.spinnerLabel = "Attempting to register domain"
	dy.addPreView(f)
	dy.addPostProcessor(registerDomain)
	q.add(&dy)
}