{{-- Fields of the campaign code form (#2957 slice 14, card #3101), shared by campaignCode/create and campaignCode/edit (the old createForm, edit and typeFields partials). Expects $campaignCode (null on create) and, on edit, $campaignData and $typeDropdown from CampaignCodeController@edit. The same names, options and defaults as before: status (Aktiv 1, Inaktiv 0), code, charges, expire_at as text in "Y-m-d H:i:s" (now when empty; the jQuery datetimepicker is gone, DESIGN.md), type (locked once companies use the code, as before), percentage_discount or flat_discount (only the one for the chosen type shows; both are posted, as before) and description (at most 30 characters). --}} @php $campaignCode = $campaignCode ?? null; $campaignData = $campaignData ?? []; $types = CampaignCode::_get('types'); $typeOptions = $typeDropdown ?? CampaignCode::typeDropdown(); $statuses = CampaignCode::_get('status'); $status = (string) old('status', $campaignCode?->status); $type = (string) old('type', $campaignCode?->type ?? array_key_first($typeOptions)); $typeLocked = $campaignCode && $campaignCode->companies()->count(); // Edit: a code that never expires stays empty (saved as null); only a new code proposes now. $expireAt = old('expire_at', $campaignCode ? $campaignCode->expire_at?->format('Y-m-d H:i:s') : date('Y-m-d H:i:00')); $discounts = [ 'percentage_discount' => ['hint' => __('campaignCode.nh.percentageHint'), 'placeholder' => 'ex. 0.2 = 20%'], 'flat_discount' => ['hint' => __('campaignCode.nh.flatHint'), 'placeholder' => 'ex. 500'], ]; @endphp @foreach ($typeOptions as $value => $name) @endforeach @foreach ($discounts as $name => $discount) @endforeach @push('scripts') @endpush